It is authentically reported that ‘Umar ibn al-Khattāb—may Allah be pleased with him—was travelling when he saw people frequenting a particular place to pray. He asked, “What is this?” They replied, “This is a place where the Messenger of Allah—may Allah bless him and grant him peace—prayed.” He said:
“Those before you perished for this very reason: they took the sites associated with their prophets as places of worship. Whoever happens to be there when prayer falls due should pray; otherwise, he should move on.”
When he learned that people were visiting the tree beneath which the Prophet—may Allah bless him and grant him peace—had received his Companions’ pledge of allegiance, he ordered it to be cut down.
Abū Mūsā sent word to him that Daniel’s grave had been discovered in Tustar, with a manuscript beside it containing accounts of future events, including accounts concerning the Muslims. He also reported that whenever the people suffered drought, they would uncover the grave and receive rain. ‘Umar sent him instructions to dig thirteen graves during the day and bury Daniel in one of them at night, so that people would not know which grave was his, lest they be led astray by it.
Thus, taking graves as places of worship is something Allah and His Messenger have forbidden, even if no mosque is built over them. Building mosques over them is graver still.
The scholars have likewise stated that building mosques over graves is forbidden, and that every mosque built over a grave must be demolished. If a deceased person has been buried in a mosque and has remained there a long time, the grave should be levelled until its outline is no longer visible, for polytheism only arises when its outline is visible.
For this reason, the site of the Prophet’s mosque—may Allah bless him and grant him peace—was originally a burial ground for polytheists, containing palm trees and ruins. He ordered the graves to be exhumed, the palm trees to be cut down, and the ruins to be levelled. It therefore ceased to be a burial ground and became a mosque.