God’s wisdom is deeper than ours. He doesn’t work by our feelings nor by appearances.
Pharaoh stood against God’s purpose in refusing to let Israel go but still remained an instrument in his hands.
The scripture makes this clear and I quote Rom 9:17
“For the scripture saith unto Pharaoh, Even for this purpose have I raised thee up that I might shew my power in thee, and my name may be declared throughout the whole earth”