Shaykh al-Islam Ibn Taymiyyah said regarding a mosque that has been built over a grave: “No obligatory or voluntary prayer may be offered there. If the mosque existed before the grave, the matter must be corrected—either by leveling the grave, or, if it is recent, by removing it. If the grave was there before the mosque, then the mosque itself must be removed, or at the very least the visible structure of the grave must be eliminated.”
Prayer is likewise invalid in any mosque whose qiblah faces a grave, because of his statement, “Do not pray facing graves.”
Prayer is not valid in al-ḥushūsh (latrines), purpose-built toilets. One must refrain from praying inside such a place because it is prepared for impurity, because the Lawgiver has forbidden the remembrance of Allah there—and prayer deserves that prohibition even more—and because latrines are frequented by devils.
Nor is prayer valid in the ḥammām (public bathhouse), a place set aside for bathing, for it is a venue where private parts are exposed and a haunt of devils. The ban covers everything enclosed by the bathhouse door; therefore, no prayer may be performed within it.