How would you feel if you spent a lot of time and effort painting a beautiful mural on the side of a building and the next day somebody came along and whitewashed over it? You’d probably be pretty miffed that someone disregarded your efforts and didn’t appreciate your handiwork. Well, God made a pretty big deal about taking us out of Egypt. How do you think it makes Him look if we turn around and go back to live there?
The reason for this mitzvah is that Egypt was a negative influence on the Jews when they lived there. According to the Zohar, they sank to the 49th level of impurity, which is just about rock bottom. God saved us from the spiritual consequences of that fate (to say nothing of the slave labor!), so we are not to willingly return there to live.
The Rambam said that if the king of Israel conquered and annexed Egypt, one would be permitted to live there. (Keep that in mind, in case it ever happens.) It’s worth noting that the Rambam himself lived in Egypt! It’s possible that he had no say in the matter; he served as physician to a sultan, who might not have permitted him to leave. It is said that while he lived there, he signed his correspondence “the one who violates three sins every day,” referring to the three places in the Torah where it says not to return to Egypt (Exodus 14:13, Deut. 17:16 and Deut. 28:68).
This mitzvah applies to both men and women in all times and places. In the Talmud, it is discussed in tractate Succah (51b). It is codified in the Mishneh Torah in the fifth chapter of Hilchos Melachim. This mitzvah is #46 of the 365 negative mitzvos in the Rambam’s Sefer HaMitzvos and #192 of the 194 negative mitzvos that can be observed today as listed in the Chofetz Chaim’s Sefer HaMitzvos HaKatzar.