If someone were to ask, “What, then, is the story of the Prophet’s grave, for we can see it today inside his mosque?” I reply: The answer lies in al-Nawawī’s commentary on Ṣaḥīḥ Muslim, where he writes:
“The scholars have explained that the Prophet ﷺ forbade turning his grave, or anyone else’s, into a mosque only out of fear that people might exaggerate in venerating it and become tempted by it, which could ultimately lead to disbelief, as happened to many previous nations. Later, when the Companions—may Allah be pleased with them all—and the Successors found it necessary to expand the Mosque of the Messenger of Allah ﷺ because the Muslim community had grown, the enlargement reached the dwellings of the Mothers of the Believers, including the room of ʿĀʾishah—Allah be pleased with her—where the Messenger of Allah ﷺ and his two Companions, Abū Bakr and ʿUmar—Allah be pleased with them both—are buried. They therefore built high, circular walls around the grave so that it would not be visible inside the mosque and the common people would not pray toward it, thereby falling into the very danger that had been feared. They next erected two additional walls, starting from the grave’s two northern corners and angling them until the walls met, so that no one would be able to face the grave directly. For this reason ʿĀʾishah said in the ḥadith: ‘Had it not been for that, his grave would have been exposed, but it was feared that it would be taken as a place of worship.’”
Citing the Companions in this narrative, however, is open to question—although al-ʿAynī follows al-Nawawī in ʿUmdat al-Qārī—because these events did not occur in the presence of any Companion. Ibn ʿAbd al-Hādī states in al-Ṣārim al-Munkī:
“During the era of the Rightly Guided Caliphs and the Companions, his chamber lay outside the mosque, and only a single wall separated them from it. The chamber was incorporated into the mosque only during the caliphate of al-Walīd ibn ʿAbd al-Malik, after the majority of the Companions who had lived in Medina had passed away. The last of them to die was Jābir ibn ʿAbd Allah, and he died in the reign of ʿAbd al-Malik—in the year…"