Since both Israel and Egypt were part of the Roman Empire and not independent countries with their own immigration laws or borders - Jesus was neither an undocumented or legal immigrant in Egypt.
If I read my bible right, the whole earth is His anyway so he can go anywhere He wants.