But You, O Lord, are a God full of compassion, and gracious, longsuffering and abundant in mercy and truth.” Psalm 86:15 (NKJV)

God is omniscient, knowing the end of a matter at its beginning. He knows what passions and thoughts drive a man’s decisions. But as a wise God, at creation, He gave man a free will. Then God laid before Adam the choice of life or death. Sadly, man chose the latter, and the God in his righteousness pronounced the death sentence upon mankind. However, at the same time, in great love God prophesied the coming of a Savior. He did so not because He suddenly changed his mind (Jesus was the lamb slain before the foundation of the earth, Revelation 13:8), but because He wanted to save Adam and his offspring from the condition of death. These experiences teach man the lessons of what sin is and the consequences of disobeying God’s will. On the basis of his experience, man learns that it is far better to choose what God desires than to sin. When man repents of sin, the response of our righteous God is to teach and comfort him – “Come near to God and he will come near to you. Wash your hands, you sinners, and purify your hearts, you double-minded,” Hebrews 4:8 (NIV).

As in the case of the nation of Israel, God was repeatedly grieved when He saw His people make mistakes. But remember: God is the God of love and forgiveness even for the heathen! Yahweh sent the prophet Jonah to tell the Ninevites that “Forty more days and Nineveh will be overthrown,” Jonah 3:4 (NIV). Why didn’t God destroy Nineveh after 40 days, as He had promised? Did God have pity on these gentiles and their fate? Yes, God forgives when He sees the penance of man – “So the people of Nineveh believed God, and proclaimed a fast, and put on sackcloth, from the greatest of them even to the least of them,” Jonah 3:5. “Should I not have compassion on Nineveh, the great city in which there are more than 120,000 persons who do not know the difference between their right and left hand, as well as many animals?” Jonah 4:11 (NASB)

Additional Resources:

A similar question arises in the context of Israel demanding a king, and God allow King Saul to reign: 
Audio Sermon: “Nay, But We Will Have a King,” Joe Megacz

Christian Questions Podcast Episode #1093: “Do Our Prayers Change God’s Mind?”
Unlocking the power of prayer and its influence on the will of God
Preview Video
CQ Rewind Show Notes