We always need to remember that Scripture wasn’t written with the mindset of a twenty-first-century person in mind and that divine revelation was not complete until Jesus Christ. Ancient Scripture speaks in ways familiar to the people of the time, and they were written taking into account what had been revealed up until that point.
The ancient world was replete with the concept that there were good gods and evil gods. The Old Testament often wanted to emphasize the Jewish people’s monotheism, and thus God was depicted as the source of all things (see Isa. 45:7). When the author says that God hardened Pharaoh’s heart, he is saying that there were no other spiritual forces (i.e., other gods) at work.
In modern theological language, and with the fullness of revelation received through Jesus Christ, we would phrase it as God permitted Pharaoh’s hardening of heart. Evil and sin are not more powerful than nor equal to God; therefore, if they exist, it is because God has permitted them to exist. This does not mean that God wills these particular things, but he permits them for a greater purpose. Generally speaking, that greater good is our free will.
As the Scriptures say, God permits the rain to fall on the good and the bad (Matt. 5:45). If God instantly punished the bad and instantly rewarded the good, there would be no free will. We would all be coerced into right action rather than freely choosing it. In this case, Pharaoh saw the goodness of God at work, and instead of accepting it chose to reject it and attack it. Sin hardens hearts and makes us less likely to repent, and God does indeed permit this if we choose.