that it is categorically forbidden (1). Others spoke of it only as something disliked. They do not regard this case as identical to the question of praying in an ordinary cemetery, for regarding that some explain the prohibition on account of the impurity of the soil, while others attribute it to imitation of the idolaters.
As for mosques built over graves, they deemed praying in them disliked, their rationale being the fear of temptation (2) through venerating a created being, as al-Shafi‘i and other leading Muslim scholars have stated.
The Prophet (peace and blessings be upon him) likewise forbade performing prayer at sunrise and at sunset, saying, “It is at those moments that the unbelievers prostrate to it.” He prohibited this because of the resemblance to their practice, even though the worshipper intends to prostrate only to the One True God (3).
= Reported by Ahmad, no. 7352; by Ibn Saʿd, 2/241-242; and by Abu Nuʿaym in Hilyat al-awliyaʾ, 7/317, with an authentic chain of transmission.
(1) The Shafiʿi school counts this act as a major sin. Al-Haytami states in Al-zawajir ʿan iqtiraf al-kabāʾir (1/120): “The third through the ninth major sins are: turning graves into mosques, lighting lamps upon them, treating them as idols, circumambulating them, touching them, and praying toward them.” Commenting on this list, Mahmud al-Alusi writes, “These words show real understanding and sound grasp of the religion” (Ruh al-maʿani, 5/31).
The Hanafis label it makruh tahrimi, a category that in their terminology amounts to prohibition. Imam Muhammad, the leading disciple of Abu Hanifa, says: “We disapprove of adding anything above what emerges from the grave, and we dislike that it be plastered, white-washed, or that a mosque be built over it” (Kitab al-athar, p. 45).
The Malikis likewise rule that it is forbidden. Al-Qurtubi states: “Our scholars hold that it is unlawful for Muslims to turn the graves of prophets or scholars into mosques” (Al-jamiʿ li-ahkam al-Qurʾan, 10/38, Dar al-Kutub al-Misriyya).
The position of the Imam of Ahl al-Sunnah, Ahmad ibn Hanbal, is also one of prohibition. Ibn al-Qayyim writes: “Accordingly, a mosque built over a grave must be demolished, just as a corpse buried inside a mosque must be exhumed. Imam Ahmad and others have stated explicitly that Islam does not allow a mosque and a grave to coexist. Whichever one preceded the other has priority; if they are established simultaneously the endowment is invalid and the prayer therein impermissible, for the Messenger of Allah ﷺ forbade that. Whoever turns a grave into a mosque or lights a lamp upon it has opposed the very religion with which Allah sent His Prophet—a religion now estranged among people, as you can see!” (Zad al-maʿad, 3/22, Kurdish ed.).
(2) This ruling comes under the principle of blocking the means (sadd al-dharaʾiʿ) that lead to polytheism. See Tafsir al-Qurtubi (2/57), Al-muwafaqat by al-Shatibi (2/241-253; 4/122), and Iʿlam al-muwaqqiʿin by Ibn al-Qayyim (3/136).
(3) For this reason, during the funeral prayer we do not prostrate; we perform it standing. The wisdom behind this—namely the absence …