—and no Muslim has ever maintained that praying or making supplication there is superior to doing so in mosques free of graves. On the contrary, the scholars of Islam unanimously agree that prayer and supplication in mosques not built over graves are better than prayer and supplication in mosques erected upon graves; indeed, performing those acts in such places is forbidden and disliked by consensus. Many of them have gone further, explicitly declaring it unlawful and even invalidating the prayer offered there—though some disagreement exists on that specific ruling. What matters here is that, by unanimous agreement, these practices are neither obligatory nor recommended; rather, they are disapproved.
He further said in al-Jawāb al-Bāhir fī Zuwār al-Maqābir:
“Prayer in mosques constructed over graves is absolutely prohibited, unlike his mosque ﷺ, where one prayer equals a thousand prayers. That mosque was founded upon piety, and its sanctity was affirmed during his ﷺ lifetime and the lifetimes of his rightly guided caliphs, before the chamber was incorporated into it.”
He then added:
“Anyone who believes that the mosque possessed no virtue before the grave was included, and that its merit arose only during the caliphate of al-Walīd when the chamber was annexed, is either grossly ignorant to the point of extremity or a disbeliever who denies what the Prophet ﵇ brought, deserving of capital punishment.”
Shaykh al-Islām, may Allah bestow mercy upon him, issued repeated legal opinions deeming it reprehensible to pray in mosques built over graves. In his Fatāwā the following question is recorded:
“Question: If a mosque contains a grave and people gather there for congregational prayer, is the prayer valid or not? And should the grave be leveled or not?”