Numerous additional ḥadīths and reports (1) address this issue, but this is not the place to cite them all in detail (2).
Consequently, every mosque erected over the graves of prophets, righteous people, kings, or anyone else must be removed, either by demolition or other means. I am unaware of any disagreement on this point among the reputable scholars. Performing the prayer inside such structures is disapproved without any known dissent, and—according to the dominant position in our school—it is invalid, owing to the explicit prohibitions and curses narrated on the matter, as well as other traditions. In this regard there is no dispute whether only one person is buried there. Our jurists differed only about an open cemetery unconnected to a mosque: does the prohibition apply once three graves are present, or is it forbidden to pray even by a single isolated grave when no other graves are near it? Two opinions are reported (3).
[Types of Prohibitions]
The prohibition becomes even more severe when the land itself is usurped. This happens, for example, when someone buried in an endowed cemetery—be he a scholar, a pious person, or anyone else—has a mosque, madrasa, ribāṭ, or shrine built over his grave, with or without the addition of ablution facilities. Such an act incorporates several distinct unlawful elements.
One of them is that an endowed cemetery may, by unanimous agreement, not be used for any purpose other than burial without compensation. Thus, constructing a mosque, school, or ribāṭ within it is akin to burying the deceased inside a mosque, or to erecting inns and the like in a cemetery, or to building a mosque in a roadway that people need for passage.