Another interpretation [of (Exodus 13:17) "And it came to pass (va-yehi) when Pharaoh let the people go"]. To what is the matter comparable? To a king whose son was taken captive. He clothed himself in vengeance against his enemies, and he went and brought him back. He took the captor and hanged him upon a gallows. He began to torment him, and he said: Why did you do this to my son? While he was tormenting him, the captor began to confess. The king said: Woe (vai) that this one has confessed! I was seeking to torment him greatly, but he confessed at once. So he gave him a sentence of reprieve. So too Pharaoh, who enslaved Israel in Egypt. The plagues began to come upon him, yet he did not let Israel go; only after all the plagues had come upon him did he begin to let them go. The Holy One, blessed be He, said: Woe (vai) that he has let them go! (Exodus 13:17) "And it came to pass (va-yehi) when Pharaoh let the people go."
Pharaoh the Captor on the Gallows and the Sigh of Va-Yehi
Midrash Tanchuma Buber, Beshalach 4:1
ד"א [ויהי בשלח]. למה הדבר דומה, למלך שנשבה בנו, לבש נקמה באויביו והלך והביאו, נטל את השבאיי ותלאו בגרדון, התחיל לצער אותו ואמר למה עשית כך לבני, עם שהוא מצערו, התחיל להודות, ואמר המלך ווי שהודה זה, הייתי מבקש לצערו הרבה והודה מיד, נתן לו אפופסין, כך פרעה שיעבד את ישראל במצרים, התחילו המכות באות עליו, ולא שילח את ישראל אלא אחר שבאו עליו כל המכות התחיל לשלחן, אמר הקב"ה ווי ששילח אותן ויהי בשלח פרעה.