Good thing Egypt didn't deport him and allowed him in
Matthew 2:
13When they had gone, an angel of the Lord appeared to Joseph in a dream. "Get up," he said, "take the child and his mother and escape to Egypt. Stay there until I tell you, for Herod is going to search for the child to kill him." 14So he got up, took the child and his mother during the night and left for Egypt, 15where he stayed until the death of Herod. And so was fulfilled what the Lord had said through the prophet: "Out of Egypt I called my son."[f]
If you knew something about the geopolitics of that time, it likely was Alexandria where they went. Alexander the Great established it as a city of refuge for Jews, under the Roman Empire. So, all would have been, ahem, kosher.
Yes, when Jesus Christ was an infant, he was taken by his parents to Egypt. But Egypt had NO law of which we are aware, prohibiting it. The United States does have laws prohibiting illegal entry, and that is the difference, almost. Joseph was commanded by direct Revelation from God to take the Child to Egypt, which would supersede any law Egypt might have had anyway.