Then he cited the last ḥadith narrated by ʿĀʾishah and said:
“Our Mālikī scholars declare: this ruling makes it unlawful for Muslims to turn the graves of prophets or scholars into mosques.”
Shaykh al-Islām likewise states in his commentary on Sūrat al-Ikhlāṣ:
“The scholars have ruled that it is forbidden to build mosques over graves, and that every mosque erected on a grave must be torn down. Even if the deceased was buried inside a mosque and a long time has passed so that the ground has been leveled and no trace of the grave remains, the place must still be cleared, for idolatry only takes hold when the grave’s form remains visible. For this very reason, the Prophet’s Mosque was originally a burial-ground for idolaters containing palm-trees and ruined structures; he ordered the graves to be exhumed, the palms to be cut, and the ground to be leveled, so that it ceased to be a cemetery and became a mosque. Because making graves into mosques and building mosques upon them is forbidden, nothing of that sort existed in the time of the Companions or the successors who followed them in excellence; a mosque upon a grave was completely unknown.”
One might imagine that the prohibition applies only when a mosque is built after a burial, and not when the mosque is first constructed and a grave is later placed beside it so that the founder—or someone else—may be buried there. Al-Shawkānī comments:
“Iraqī said: The apparent evidence shows no difference at all: if a mosque is built with the intention that someone be buried in part of it, the act falls under the curse. Indeed, burial inside a mosque is forbidden, and any stipulation that someone be buried there is invalid because it contradicts the very condition of endowing the place as a mosque. Allah knows best.”