The Torah prohibits returning to Egypt (Deuteronomy 17:16, Sefer HaMitzvos Lo Sa'aseh § 46). The Sefer HaChinuch § 500 explains the reason for the prohibition is because the Egyptians are bad people, and Hashem doesn't want us to learn from their ways, considering He took us out from there in the first place.
Some want to explain that the Torah only forbade returning to Egypt via the path the Jews took in the wilderness during their 42 journeys (Divrei Shaul to Numbers 33:1,2, brought by the Toafos Re'eim to Sefer Yereim § 309 (303); see there his question on this). Some want to say the Ritva's understanding of the Yereim implies this as well. I've also heard some more recent divrei Torah quoting this idea. As an aside, this answers how the Rambam himself could live in Egypt (see here).
However, this seems extremely specific. Why would the Torah prohibit only this path, yet if a person is missing even one of the stops, it's totally fine to return to Egypt?