In the next few weeks' Parshiyot, Hashem punishes the Egyptians and Paroh for the all the terrible things which they did to Bnai Yisrael. In Parshat VaEra and Parshat Bo, Hashem brings the עשר מכות, and in Parshat Beshalach, Hashem drowns the Egyptians in the Yam Suf. One question which must be raised is why the Egyptians were punished. if Hashem hardened Paroh's heart. In fact, before the Makkot even begin Hashem tells Moshe ואני אקשה את לב פרעה, "I will harden Paroh's heart" (שמות ז:ג). If Paroh, then, had no choice in the matter how could he be punished? The only time we take into account שכר ועונש, reward and punishment, is if there was בחירה חפשית, freedom of choice, and Paroh didn't have this freedom.
Rashi (בראשית יח:ה ד"ה וסעדו) writes that since the Pasuk says לבכם with one Bet and not two, we see that מלאכים, angels, don't have a Yetzer Hara. This may be the reason why they also don't have שכר ועונש, as a result of the fact that by nature they do what is right. It is only when someone grapples with the decision of doing good or bad that we can reward or punish him for what course of action he has chosen. Similarly, the Ramban (דברים ל:ו ד"ה ומל) writes that in the times of the Moshiach everyone will go back to the state they were in before Adam was kicked out of גן עדן. That is, everyone by their very nature will do what is right, without any inkling to sin. For this reason, the Ramban writes, there will also not be any reward and punishment. If this is true, how could Hashem punish Paroh and the Egyptians for what they did if they didn't have any choice in the matter?
The Rambam (הל' תשובה פרק ז הלכה ג) writes that it is possible that a person will commit such a severe sin or sins that Hashem closes the doors of Teshuvah from him. He writes that this is what happened with Paroh. Paroh sinned by himself originally by doing so many bad things to Bnai Yisrael who were living in his land, and because of this Hashem punished him by closing the doors of Teshuvah from him. Hashem punished Paroh because of what he did on his own previously, and only later on he hardened his heart in order to prevent his Teshuvah. The Ramban quotes this as well in his commentary on the Chumash.
The Ramban, however, offers a second interpretation to this question. He explains that it was only in the last five Makkot that it says Hashem hardened his heart. However, in the first five Makkot Paroh made his own decision not to grant permission to Bnai Yisrael to leave. After the first five Makkot, Paroh was willing to let Bnai Yisrael go, but for the wrong reasons. He would have let them leave because he couldn't stand the Makkot anymore, and not because he realized that Hashem was the true Creator. For this reason, Hashem hardened Paroh's heart so that he would let them go for the right reasons. Nonetheless, the punishment came because of Paroh's horrible actions which he did on his own.