How could Maimonides live in Egypt? – Ask the Rabbi
Radbaz (16th cent.) said that Maimonides did not really want to live in Egypt, but he had to because his court post required it.
Maharshal (17th cent.) thought Maimonides had an ulterior motive for staying in Egypt, hoping that his public eminence would persuade the regime to facilitate a Jewish return to Israel.
Another comment by Maharshal is highly poignant, saying that in a harsh world Jews cannot be too fussy as to which country they reside in. But wherever we are, we have always been good citizens and contributed to the enhancement of society.