Good question. Here are two answers to your question. Maimonides writes that it was a punishment for not heeding the previous warnings and not freeing the Jewish slaves. Therefore, Pharaoh lost his right to free will and became a puppet in the hand of God.
Another answer is very different and esoteric. It was not a punishment, but rather a way to balance his thinking and give him a fair chance to make the correct decision. Without a ‘hardened heart’ he certainly would have freed the Jewish slaves after suffering the previous plagues. It was a no brainer decision that he’d make and would not even be a real “choice”. By hardening Pharaoh’s heart, God actually gave back to Pharaoh his free will to react as he really wanted rather than reacting due to being overpowered by the might of God.
That is to say that God didn't force Pharaoh to say "No." He simply gave Pharaoh the opportunity to do so. Nothing but his own stubbornness stopped Pharaoh from repenting. The essence of the second idea is that without the hardening of the heart Pharaoh would have thrown the Jewish People out immediately. Not because he believed that God was right but only because he knew that God was infinitely stronger than him.