Thus, the wisdom of the Almighty—blessed and exalted—after sending Muhammad (peace and blessings be upon him) as the last of the messengers and making his law the final revelation, required that He forbid every means that might, even in the distant future, become a pathway leading people into idolatry, the greatest of all major sins. Therefore He prohibited building mosques over graves, just as He forbade traveling to them, turning them into recurring festivals (1), or swearing oaths by those buried there. All such practices foster excess and end in worshipping them instead of Allah Most High—especially when knowledge dies out, ignorance spreads, sincere advisers are few, and the devils of jinn and humankind collaborate to mislead people and drive them away from the worship of Allah.
(1) Al-Nawawi, in the section on the etiquette of visiting the Prophet’s grave within his work Manasik al-Hajj (2/69), preserved in manuscript form at the Zahiriya Library in Damascus (Ms. 3656), reports: Malik, may Allah have mercy on him, considered it disliked for the residents of Madina to stop at the grave each time they entered or left the mosque; he held that such standing is intended for visitors from outside. He added that there is no objection if someone who has just arrived from a journey—or is about to set out—stands at the grave of the Prophet, invokes blessings upon him, and supplicates for Abu Bakr and Umar, may Allah be pleased with them both. Al-Baji explains that Malik differentiated between Madina’s inhabitants and travellers because the latter come expressly for this purpose, whereas the former live there permanently; and the Prophet said: “O Allah, do not turn my grave into an idol to be worshipped.”