It's up there in the annals of stupidity.
God had just undone Egyptian society with 10 devastating plagues, striking at the heart of Egypt's various nature gods. Water turned to blood. Animals turned against humans. Light stopped working. Pharaoh's Egyptian experiment, for all intents and purposes, was done for, shattered with ease by a God that had clearly marked it for destruction.
And then Pharaoh led his army into the ocean.
Had it not been made clear to him that it was over? What person in his right mind, who had just experienced what Pharaoh had experienced, would see the Jews walking through dry land, in the midst of ocean, and think, "It's a good idea to send the remainder of my army after them?" It's nuts. A 5-year-old reading this story for the first time could've predicted that the walls of water would crash down once the Egyptians went in. Why couldn't Pharaoh?
Because he was a man addicted to Id.
Id is what psychoanalyst Sigmund Freud said is the base component of personality. It's the instinctual force in our lives that seeks, without the balancing, realistic, force of ego, to maximize pleasure.
Throughout the Exodus story, God's "hardening" Pharaoh's heart can be understood as God giving Pharaoh's Id a chance to fight against the ovewhelming force of Godly revelation. Pharaoh's instinct, like that of many political and military leaders, is to react with fury against threats. God, for Pharaoh, was the ultimate threat, but not one that he would have had the freedom to respond to, unless, as many scholars have pointed out, God hardened his heart and gave him the ability to resist.
As a creature of Id, Pharaoh repeatedly acted on his instincts, on his nature, on his built-in drive. His reaction to the plagues, until the final one, was to lash out at God, maintain control over the Jews, and even increase their burden.
For Pharaoh, until the death of the firstborn, he was resolved to fight back against this foreign power, God, who was trying to unseat him. The 10th plague changed that because it deflated him and his Id. But Pharaoh's letting the Jews go after the death of so many Egyptian firstborns, children and adults, was not a triumph over his Id--it was another subjugation to it. He felt emotionally exhausted and he crumbled to his natural will, just as he crumbled when he felt emboldened and enraged at the previous nine plagues.
All his Id needed to prod Pharaoh was some time. Once it recovered from the blow of the 10th plague, it realized that losing the Jews meant losing enormous power and credibility, which is what Pharaoh's Id thrived on.
So, when Pharaoh pursued the Jews to the sea, and saw that his biggest sources of pleasure, his slaves, were making their way through the ocean, his Id kicked into full gear and foolishly chased them. Again, Pharaoh's Ego and his common sense utterly failed him. It was the ultimate victory of Id. The greatest empire of that time, Egypt, was brought to its knees not just by God, but by Pharaoh too. Had Pharaoh succumbed earlier on, say, when the frogs went haywire, the Jews would have left, and Egypt's wise men would have figured out another way to maintain dominance.
The Torah states explicitly (Exodus 10:7) that Pharaoh's servants told him after the eighth plague, "Do you not yet know that Egypt is destroyed?!" He did know, but his Id blinded him. He lost everything because he couldn't fight instinct. Pharaoh is one of Torah's ultimate warnings to humanity: balance your natural instincts with something higher, or they will ruin you, whether you are running an empire, or just your own life.
Thankfully, this element of Passover is not only a warning. Even on a basic, textual level, God gave Pharaoh plenty of opportunities to rise above his Id. He strengthened his Id in order to give Pharaoh a true chance to rise above it. Passover is not only about the Jews, it's about how God tried repeatedly to help one of His most wicked creations to rise above his Id. In Exodus, Pharaoh failed to do so.
But according to Jewish oral tradition, the Midrash aggadah, God did not give up on Pharaoh. The Midrash holds that Pharaoh was the king of Nineveh, the city that Jonah was called upon to save. Whether the Pharaoh of NIneveh and the Pharaoh of Egypt were the same person is, for this point, not relevant. The Midrash clearly had something deeper in mind than textbook accuracy when determining that Pharaoh ruled Nineveh.
Upon hearing Jonah's warning that Nineveh must repent, the king, Pharaoh, performed the ultimate act of tshuva, repentence. He was again confronted by a prophet of God, and again warned that he must change his ways. This time, Pharaoh did what he could not bring himself to do in Egypt. He overcame his Id and ordered the entire city to fast, declaring that there is one God whose words are the truth.
Faced with the same dilemma, Pharaoh became the person God wanted him to be all along.
It's a beautiful idea. Passover was not just about the Jews. And Nineveh was not just about its people or about Jonah. God wanted Pharaoh to redeem himself and he presented him with opportunity after opportunity to do it until, at Nineveh, he finally rose above his instincts.