I believe Psalm 66:18 states that if I am living in willful rebellion to God's will, that the Lord cannot hear my prayers, unless of course it is to cry out for repentance. But if I am obedient, will God answer all my prayers?
In Psalm 66 the psalmist testifies of the faithfulness of God. He reports that he cried to the Lord from oppressive circumstances, and his calls were met with a blessing. In v.12 the psalmist said the Lord rescued His people and brought them into a place of abundance, referring to the Promised Land. The Lord always works in the best interests of Israel, which is why in v.9 the psalmist says the Lord will not allow His people’s feet to slip.
This same principle applies to answering prayer. The Lord will not grant evil desires because they would not serve God’s purposes for His people. With that in mind, the psalmist declares:
Psa. 66:16 Come and hear, all who fear God,
And I will tell of what He has done for my soul.
Psa. 66:17 I cried to Him with my mouth,
And He was extolled with my tongue.
Psa. 66:18 If I regard wickedness in my heart,
The Lord will not hear;
Psa. 66:19 But certainly God has heard;
He has given heed to the voice of my prayer.
Psa. 66:20 Blessed be God,
Who has not turned away my prayer
Nor His lovingkindness from me.
Calling to the assembly of God’s people, he declares that he will tell of all that God has done for his soul. He cried to the Lord by his mouth and praised Him with his tongue. But the Lord’s response to his prayers is always dependent on what is best for His people.
When God’s people make evil requests of the Lord, the Lord rightly will not hear such things, for if He were to hear (i.e., agree) to such requests, He would bring evil things upon His people. Technically speaking, the Lord hears all the prayers of His children (e.g., Psa 116:1; Prov 15:29, etc.), but the question the psalmist is posing is what petitions will the Lord grant?
The psalmist says the Lord will not grant petitions when he regards (looks upon) evil. If the psalmist’s petitions come out of sinful desires, the Lord could not grant them. The Lord did not hear them in that sense. But the psalmist says he prayed for righteous outcomes and therefore the Lord granted them.
This is a basic principle of prayer. The Lord accomplishes His will through our prayers by affirming our righteous requests while dismissing our unrighteous requests or those that are not according to His will. We should expect no less from a God Who loves us and desires what is best for us.