The Rambam, according to almost all Mepharshim, held that Jews from Iraq could not leave, including to Israel, until the Mashiach. Obviously Iraq’s Jews all left after Israel was founded and anti-Semitism increased in the area. Following the Rambam, was this transgressing the mitzva of staying in Iraq? And should we as religious Jews, have been more mindful to the effect that setting up a state would have for the Jews in Arab lands, especially Iraq?
Firstly, your understanding of the Rambam is that of the Kesef Mishneh, but from what I saw, davka most (Aruch HaShulchan, Even HaEzel and many others) understand the more logical explanation: that the Rambam is not contradicting himself (for he writes there that all Jews should always live in Israel), but it's referring to not leaving Bavel for other lands, aside from Israel. Even according to your understanding, the Holy Shla (Torah sheB'Chtav, Kedushat haAretz, 11b) answered your question already 450 years ago, when he explains midrashically that in Avraham's righteousness, he tried to be stringent and fulfill even minority opinions, even before the Torah was given! Accordingly, he was concerned about that opinion cited in the Rambam & thought not to make Aliya to Israel, but rather stay in Bavel. But when Nimrod threw him into the burning furnace, Avraham understood that it's a sign from God not to worry about it, and to make Aliya. Eerily, the Shla mentions there (!) the instruction that "what happened to our fore-fathers will happen again to their offspring", and 3700 years after Avraham, his descendants (many of who also deliberated whether to wait for mashiach or to make aliya and bring him), were thrown into the burning furnaces of Europe, and were left no choice, but to run to the Land of Israel. The subsequent fires of war forcing Jews to leave Iraq, leaving hundreds of millions dollars-worth of their possessions, is no different. We firmly believe that God runs history, and today, with no prophets or Sanhedrin, He "solves" many halachic questions through such historic necessities (see: http://direct.yeshiva.org.il/ask/nihul/Eadmin_search_ask.asp?E=&srch=1&q=hasagat+gvul ). Similarly, God solved the rabbinic debate, of whether to actively build a Jewish State or not, through the secular Zionists, who simply didn't ask the rabbis (who otherwise, would still be debating until today!). Also, the Rambam doesn't mention Mashiach there, and if he writes subsequently that a person should live in Israel, apparently, he meant to be in Bavel until God shows us that it's time to leave, as He did by Avraham. Also, many explain that gemara, the Rambam's source, in that Bavel/Iraq was the Torah center of the world, but over the past 1,000 years, it's been relocated to Morocco, France, Spain, East Europe and today, the center has not coincidentally returned forever to where it started, in Israel. That gemara would be another reason today davka to make Aliya, and surely not to stay away! By the way, that understanding of the Rambam is omitted in the Shulchan Aruch and all halachic codifiers, and surely is superseded by the dire necessity of declaring the Jewish State which, as expected, has saved millions of lives. But ironically, just in case you were in doubt, the Shla answers you. In short, God has shown us over the past century, that the Jews of Iraq together with the rest of the Jews from Asia, Africa, Eastern and Western Europe, and really all Jews are expected to make Aliya (and BH most are already here). Children of Israel, our Father is calling us to come Home. Rav Ari Shvat