"In those days Hezekiah became mortally ill. And Isaiah the prophet the son of Amoz came to him and said to him, "Thus says the Lord, ‘Set your house in order, for you shall die and not live.’" 2Then he turned his face to the wall, and prayed to the Lord, saying, 3"Remember now, O Lord, I beseech Thee, how I have walked before Thee in truth and with a whole heart, and have done what is good in Thy sight." And Hezekiah wept bitterly. 4And it came about before Isaiah had gone out of the middle court, that the word of the Lord came to him, saying, 5"Return and say to Hezekiah the leader of My people, ‘Thus says the Lord, the God of your father David, "I have heard your prayer, I have seen your tears; behold, I will heal you. On the third day you shall go up to the house of the Lord. 6"And I will add fifteen years to your life, and I will deliver you and this city from the hand of the king of Assyria; and I will defend this city for My own sake and for My servant David’s sake,"’" (2 Kings 20:1-6).
Here we see an example of God listening to the prayer of someone and then apparently changing His mind about a course of action that He said He would do. Does God actually change His mind? The answer is yes and no.
From all eternity God knew exactly what was going to happen and had planned to "change His mind" when Hezekiah prayed. This means that God works in real time and purposely responds to the prayers of His people and then appears to change His mind when people pray. This is one of the points of the text -- that God hears our prayers and responds to them. We are not robots, and God is not inflexible. Yet, at the same time, God knows all things (1 John 3:20; John 21:17). So, even though God knows what will ultimately happen, that doesn't mean He can't respond to our prayers, which is part of His plan that brings about what will ultimately happen.
Furthermore, it says in 1 Sam. 15:29, “And also the Glory of Israel will not lie or change His mind; for He is not a man that He should change His mind." We can see that the Bible tells us God does not change His mind, yet we see how He seems to do just that. Again, the answer is found in looking at the problem from two perspectives. From the eternal perspective, God does not change His mind since He knew from all eternity what the ultimate decision would be. From the temporal perspective (relative to us), God changes His mind in response to the prayers and pleading of His people.