Deuteronomy 17:16דברים י״ז:ט״ז
Moreover, he shall not keep many horses or send people back to Egypt to add to his horses, since יהוה has warned you, “You must not go back that way again.”
Exodus 14:13שמות י״ד:י״ג
But Moses said to the people, “Have no fear! Stand by, and witness the deliverance which יהוה will work for you today; for the Egyptians whom you see today you will never see again.
Deuteronomy 28:68דברים כ״ח:ס״ח
יהוה will send you back to Egypt in galleys, by a route which I told you you should not see again. There you shall offer yourselves for sale to your enemies as male and female slaves, but none will buy.
Mekhilta DeRabbi Shimon Ben Yochai 14:12מכילתא דרבי שמעון בן יוחאי י״ד:י״ב
...
Mishneh Torah, Kings and Wars 5:7משנה תורה, הלכות מלכים ומלחמות ה׳:ז׳
It is permitted to dwell anywhere in the entire world with the exception of the land of Egypt. Its territory includes a square of 400 parsah by 400 parsah from the Mediterranean Sea proceeding westward, bordering on the land of Kush and the desert. It is forbidden to dwell in this entire territory.
In three places, the Torah warned against returning to Egypt:
a) 'God has told you, you must never again return on that path' (Deuteronomy 17:16 ;
b) 'You shall not see it again' (Deuteronomy 28:68 ;
c) 'You shall never see them again forever' (Exodus 14:13 .
Alexandria is included in this prohibition.
In three places, the Torah warned against returning to Egypt:
a) 'God has told you, you must never again return on that path' (Deuteronomy 17:16 ;
b) 'You shall not see it again' (Deuteronomy 28:68 ;
c) 'You shall never see them again forever' (Exodus 14:13 .
Alexandria is included in this prohibition.
Mishneh Torah, Kings and Wars 5:8משנה תורה, הלכות מלכים ומלחמות ה׳:ח׳
It is permitted to return to Egypt for the purpose of trade and commerce and to pass through while conquering other nations. The prohibition consists of settling there.
Lashes are not given as punishment for the violation of this prohibition because at the time one enters, there is no prohibition. Should he decide to settle there, there is no deed involved.
It appears to me that if a king of Israel would conquer the land of Egypt with the approval of the court, it would be permissible to settle there. The prohibition against returning was only given to individuals or to dwell there while it is under the rule of the gentiles for their behavior is more depraved than that of the peoples of other lands as can be inferred from Leviticus 18:3: 'Do not follow the ways of Egypt....'
Lashes are not given as punishment for the violation of this prohibition because at the time one enters, there is no prohibition. Should he decide to settle there, there is no deed involved.
It appears to me that if a king of Israel would conquer the land of Egypt with the approval of the court, it would be permissible to settle there. The prohibition against returning was only given to individuals or to dwell there while it is under the rule of the gentiles for their behavior is more depraved than that of the peoples of other lands as can be inferred from Leviticus 18:3: 'Do not follow the ways of Egypt....'
Jerusalem Talmud Sukkah 5:1:5תלמוד ירושלמי סוכה ה׳:א׳:ה׳
Rebbi Simeon ben Yoḥai said, at three places were Israel warned not to return to the land of Egypt, [as it is written:] for as you saw Egypt today you shall nevermore see them for ever. And the Eternal said to you, you shall never again return on this way. And the Eternal will bring you back to Egypt on ships. In all three cases they returned and in all three cases they fell. One in the days of Sanherib the king of Assyria, [as it is written]: woe on those who descend to Egypt for help. What is written after this? But Egypt is human and not god, and their horses are flesh, etc. And one in the days of Joḥanan the son of the bald; it shall be that the sword which you are fearing, there will reach you. And once in the days of the evil Trajanus.
Jerusalem Talmud Sanhedrin 10:8:4תלמוד ירושלמי סנהדרין י׳:ח׳:ד׳
Totally, for the Eternal. your God. Nothing of what should be destroyed shall stick to your hands. It was stated: Rebbi Simeon ben Eleazar says, they did not rebuild it but built another town. After it was built, you are permitted to dwell there. Rebbi Yose and Rebbi Joshua ben Qorḥa say, why does the verse say, who would build this town, Jericho? That one may not build another town and call it Jericho, or Jericho and call it another town. And so He says, you shall not continue to return on this way, you may not return for dwelling; you may return for peddling, business, or to conquer the land.
Sefer HaChinukh 500:1ספר החינוך ת״ק:א׳
To not ever dwell in the Land of Egypt: That we not further go back on the way to Egypt ever; meaning to say that we do not establish our residence in Egypt. And about this is it stated (Deuteronomy 17:16), “and the Lord said to you, ‘You shall not further go back on this way again.’” And the prevention of this is repeated three times: They, may their memory be blessed, said (Mekhilta DeRabbi Yishmael 14:13:2), “In three places did the Torah warn not to return to the Land of Egypt [...] In the three they returned, and in the three they were punished.” And these three places [are] the one we mentioned; the second is “by the way that I said to you, ‘You shall not further again, etc.’” (Deuteronomy 28:68); and the third is “as that which you see Egypt today, you shall not further, etc.” (Exodus 14:13) — and even though it appears to be [only] a story from its revealed meaning, the tradition comes about it that it is a prevention (a negative commandment).