Exodus 7:3 says, “But I will harden Pharaoh's heart that I may multiply My signs and My wonders in the land of Egypt.”
And yet, Psalm 95:8-10 says, “Do not harden your hearts, as at Meribah, As in the day of Massah in the wilderness, "When your fathers tested Me, They tried Me, though they had seen My work. "For forty years I loathed that generation, And said they are a people who err in their heart, And they do not know My ways.”
So why did God harden Pharaoh’s heart, especially in light of Psalm 95, where God commands people not to harden their hearts?
The Bible says that, after the plague of blood, Pharaoh’s heart became hard; he would not listen; he turned, went into his palace, and did not even take this to heart. Later, after the plague of frogs, the Bible reports Pharaoh as saying, ‘I will let your people go; but when he saw relief, he hardened his heart and would not listen.’ After the plague of gnats, the Pharaoh still would not listen. Nine times in Exodus, the hardening of Pharaoh’s heart is ascribed to God. Another nine times, the Pharaoh is said to have hardened his own heart. However, a careful examination shows that the Pharaoh alone was the agent of the hardening in each of the first five plagues. Not until the 6th plague did God confirm the Pharaoh’s willful action. Soft soil allows plants to be planted and grow, while hard, dry soil does not allow for the easy growth of plants. The seed of faith could not take root in the hard, dry soil of Pharaoh’s heart. So, then, why did God harden Pharaoh’s heart? He simply reinforced the attitude that Pharaoh already had. God was the One Who brought the plagues, so God could keep Pharaoh’s mind from being changed by them. Ultimately, it was to glorify the Name of the only One Who rightfully deserves to be glorified and praised. In order for God to demonstrate His glory (and His power over all the Egyptian gods, because each of the plagues was directed toward specific Egyptian gods) and bring about all the plagues He had planned to demonstrate, Pharaoh had to be held back until the last plague was complete.
Romans 9:14-27 says:
“What shall we say then? There is no injustice with God, is there? May it never be! For He says to Moses, "I WILL HAVE MERCY ON WHOM I HAVE MERCY, AND I WILL HAVE COMPASSION ON WHOM I HAVE COMPASSION." So then it does not depend on the man who wills or the man who runs, but on God who has mercy. For the Scripture says to Pharaoh, "FOR THIS VERY PURPOSE I RAISED YOU UP, TO DEMONSTRATE MY POWER IN YOU, AND THAT MY NAME MIGHT BE PROCLAIMED THROUGHOUT THE WHOLE EARTH." So then He has mercy on whom He desires, and He hardens whom He desires. You will say to me then, "Why does He still find fault? For who resists His will?" On the contrary, who are you, O man, who answers back to God? The thing molded will not say to the molder, "Why did you make me like this," will it? Or does not the potter have a right over the clay, to make from the same lump one vessel for honorable use and another for common use? What if God, although willing to demonstrate His wrath and to make His power known, endured with much patience vessels of wrath prepared for destruction? And He did so to make known the riches of His glory upon vessels of mercy, which He prepared beforehand for glory, even us, whom He also called, not from among Jews only, but also from among Gentiles. As He says also in Hosea, "I WILL CALL THOSE WHO WERE NOT MY PEOPLE, 'MY PEOPLE,' AND HER WHO WAS NOT BELOVED, 'BELOVED.'" "AND IT SHALL BE THAT IN THE PLACE WHERE IT WAS SAID TO THEM, 'YOU ARE NOT MY PEOPLE,' THERE THEY SHALL BE CALLED SONS OF THE LIVING GOD." Isaiah cries out concerning Israel, "THOUGH THE NUMBER OF THE SONS OF ISRAEL BE LIKE THE SAND OF THE SEA, IT IS THE REMNANT THAT WILL BE SAVED.”
(The above information is from BSF Notes, BSF International, Lesson 7, “Battle Against the Gods of Egypt – Exodus 6:28-10:29,” as well as NIV footnotes and my own notes)