Both reports are sound, and we have already documented their chains along with several other narrations in the section, “Prayer in Mosques Built over Graves.”
These hadith establish the prohibition of constructing mosques over graves, for the very act of building is one of the ways a grave is turned into a place of worship, as was explained earlier. One wording even states this explicitly:
Sound: “They built a mosque over his grave and fashioned those images inside it; such people will be the worst of Allah’s creation on the Day of Resurrection.”
Al-Bukhari and Muslim both recorded this narration.
A great number of scholars have adopted the view of prohibition. Imām Muhammad said in his book al-Āthār:
“We do not consider that anything be added to what has come out of it (the grave), and we deem it disliked to plaster it, coat it with clay, or to make a mosque at it.”
When he uses the term “disliked” (makrūh) without qualification, he intends a ruling of prohibition.
Al-Shāfiʿī, for his part, wrote in al-Umm:
“I dislike that a mosque be built upon a grave. I dislike it because of the Sunnah and the reports, and—Allah knows best—he disliked that any Muslim be exalted to the extent that his grave is taken as a mosque, for fear that those who come after might fall into temptation and misguidance.”
And in al-Majmūʿ: