The Rambam is of the view that prophecy is a level of human perfection that any person can, in theory, attain by rising to a high moral and intellectual level. When a person reaches this lofty level, he will attain a prophetic connection to God. However, God retains the right to sever that connection if He sees fit. This general understanding is reflected in many of the Rambam’s writings, from his Shemonah Perakim to his Mishneh Torah to his Moreh Nevukhim. (There is, however, a different understanding of Rambam’s view – that God must bestow prophecy on a deserving individual rather than actively remove it from those otherwise deserving. See Lehem Mishneh, Hilkhot Yesodei Ha-Torah 7:1.)
Thus, for example, the Gemara (Sanhedrin 11a) states that Hillel and Shmuel Ha-Katan were worthy of attaining prophecy but that their generations did not deserve having among them a prophet. These individuals had reached the status of prophecy but God withheld it because of their neighbors.
The Rambam explains why there is no longer, during the long exile, any prophecy:
The same circumstance, prevalence of sadness and dulness, was undoubtedly the direct cause of the interruption of prophecy during the exile… This is a real fact, and the cause is evident; the pre-requisites [of prophecy] have been lost. In the Messianic period – may it soon commence – prophecy will therefore again be in our midst, as has been promised by God. (Moreh Nevukhim II:36)
In other words, the travails of exile prevent individuals from attaining the necessary level for prophecy. This explains why the Rambam did not mention in Mishneh Torah that prophecy cannot take place outside of the land of Israel, even though it seems to be an undisputed statement of Hazal. According to the Rambam, this is not a rule of prophecy but a reality of exile. Exile prevents a person from acquiring the prerequisites of prophecy. However, I was bothered for a long time why the Rambam needed this roundabout approach.
I recently discovered that R. Yitzhak Arama took the general approach of the Rambam to prophecy but addressed this particular issue differently. According to R. Arama (Akedas Yitzhak, Balak ch. 82), God intentionally removes prophecy from those in exile. One can ask why God does this, and there are many possible answers. Perhaps it is to emphasize the special character of the land of Israel. Or perhaps it is part of God’s plan for a degeneration of divine revelation until messianic times. But, regardless, it seems to me that this is a more palatable mechanical explanation of why there is no prophecy in exile.