Moses does not pray inside Pharaoh's palace. He does not pray inside the city at all.
"When I have gone out from thee into the city," he tells the king, "I will outspread my hands in prayer before the Lord, and the thunders shall cease, and there shall be no more hail; that you may know that the earth is the Lord's" (Targum Pseudo-Jonathan on Exodus 9:29).
The Aramaic paraphrase, preserved in the Targum attributed to Yonatan ben Uzziel, emphasizes the phrase arka d'Hashem hi — the earth is the Lord's. The whole earth. Including this stretch of soil outside the city where a prophet is about to raise his hands. Including the palace where a king is cowering. Including the fields where the hail is still shredding the grain.
Why pray outside the city? The sages offered several reasons. Egypt's cities were full of idols and ritual impurity, and Moses wished to turn his face only toward the Holy One, unobstructed. And there was a symbolic reason: Pharaoh had to know that the God of Israel did not need an Egyptian temple, an Egyptian altar, or an Egyptian throne-room to be heard.
The Maggid teaches: the prayer of a righteous person needs no architecture. A field, two open palms, and a heart turned to heaven are enough to stop the sky.