"They should take some of the ashes of the burnt purification offering [of the red cow] and place them in a vessel [filled] with spring water" [Chukat 19:17]
Rambam comments: "Nine red heifers were prepared from the time this mitzvah was given until the destruction of the Second Temple. The first was prepared by Moshe, the second by Ezra, and there were seven from Ezra until the destruction of the Temple. The tenth will be made by King Mashiach - May he be speedily revealed! Amen, may this be your Will!"
The fact that Rambam mentions the tenth red heifer that "will be made by King Mashiach" in his legal Code [the Mishneh Torah] is understood, since Rambam included in his Code many laws that will only be applicable in the future era. What is difficult to comprehend is why he concluded this law with a prayer "May he be speedily revealed! Amen, may this be Your Will!" Surely a legal Code is not the place for the author to record his personal emotions and feelings, or to lapse into prayerful wishes?
It could be argued, however, that with his "prayer", Rambam did teach us a point of Jewish Law - or, to be precise, three points:
Judaism requires a person:
1) Not merely to believe [intellectually] in Mashiach, but also to actively await and yearn [emotionally] for his coming [Laws of Kings 11:1]
2) Inevitably, feeling this void will lead a person to pray for Mashiach's coming, just as he prays for any other thing that is lacking in his life.
3) And being that the requirement to believe in Mashiach is in force at all times, it follows that likewise, a person must yearn and pray for Mashiach constantly.
1) Rambam included prayerful wishes here in his legal Code to indicate that awaiting Mashiach must not be only expressed intellectually, but emotionally too.
2) He stresses that Mashiach should come "speedily" to indicate Mashiach's coming should be a personal heartfelt desire.
3) He recorded the above principles, not in his codification of the laws concerning Mashiach, but here out of context, to indicate that one must express a yearning for Mashiach constantly, whatever the context of one's discusion happens to be.
Source: Likutei Sichos of the Lubavitcher Rebbe