The comment about Alexandria is because that was the center of the Jewish community in Egypt in historical times:
Where does that prohibition come from? One of the Rambam’s three sources is from this week’s parasha:
At first glance, this seems like a promise, not a commandment—you will not see Egypt this way, not you shall not. We saw this ambiguity between promise and command when we looked at תשובה, in parashat נצבים-וילך. The Mechilta interprets this as a commandment:
Back in our pasuk, Rashi interprets this as a promise that Egypt will never threaten Israel militarily again:
And the Ramban has a problem with the “commandment” interpretation:
And the Rambam himself, who lists this as a Biblical prohibition, lived most of his adult life in Egypt. The commentators on the משנה תורה address this:
And the Rambam seemed to acknowledge the problem:
The Ramban tries to put the two interpretations together and understand the prohibition as a whole:
In other words, our pasuk לא תוסיפו לראותם by itself, as פשט, is a promise that they would never be threatened. The pasuk in דברים says וה׳ אמר לכם to teach that just like this is a commandment, so to the first time it was said, it was also a commandment. But the commandments are subtly different. In שמות, the commandment is not to be intimidated by Egypt’s might and military prowess into moving there or even allying with them. This was the sin mentioned in the Mechilta in the days of סנחריב.
The prohibition in דברים is not to be impressed with Egypt’s wealth and culture, as symbolized by their horses. This was the sin of the Jews of Alexandria, who were assimilated into contemporary Egypt.
And the third warning against moving to Egypt? That is part of the תוכחה, the prophecy of the punishments that will come if בני ישראל violate the Torah. It’s not a commandment but a warning: והשיבך ה׳ מצרים באניות בדרך אשר אמרתי לך לא תסיף עוד לראתה. How could the Jews be blamed for that?
The answer is in another pasuk, the prohibition of destroying the altar:
So the prohibition is less “don’t move to Egypt” but “don’t do the sorts of things that will lead inevitably to your exile back into Egypt”. And that was the sin in the days of יוחנן בן קרח when the remnants of the Jewish community ended up in Egypt after the destruction of the first בית המקדש and the murder of גדליה.
So there are three reasons why we end up under the influence of Egypt and societies like her. And in all three cases, ה׳ warns us to maintain our identity and independence, so that we do not end up “all washed up” like Pharoah and his chariots in ים סוף.