Question :
"When (the people of the city) disputed of their case among themselves, they said: Build over them a building. {Al-Kahf, 21}. Does this verse refer to the permissibility of building mosques over graves, as is the case in several Muslim countries? And does Islamic Sharia approve of this?
The Answer :
Praise be to Allah, the Lord of the Worlds.
The mosque is a place endowed for prayer, and having a grave in it doesn`t make it other than a mosque, and this involves two situations:
First: The grave is next to the mosque, which is permissible, even if that grave was in the direction of the Qiblah so long as the mosque`s wall separates it from the grave. Al-Menawi said: "There is no sin on whoever built a mosque next to the grave of a righteous man or prayed beside it." {Fayeid Al-Khadeer, 4/612}. And the same ruling applies when the grave is located in the yards of the mosque that aren`t set for prayer.
Al-Mabarkfoori (May Allah have mercy on him) said: "It is stated in Majma` Al-Bihaar: The narration: 'Allah cursed the Jews and the Christians because they took the graves of their Prophets as places for praying." The one who built a mosque next to the grave of a righteous man or prayed beside it incurs no sin. For example, Hijr-Ismail (Stone of Ismail) in Al-Masjid Al-Haraam." {Tohafat Al-Ahwathi, 2/226}.
If we take a look at the shrines of the Prophets and the Companions, we realize that the graves themselves are separated from the place of prayer. Not only this, but also the graves are contained in special chambers. This way, the mosque isn`t built over the graves and the latter are located next to the mosque. As for {Build over them a building}, Al-Shirbini said: " {When (the people of the city) disputed of their case among themselves}, it refers to the group of youths who hid in the cave.i.e. the believers. {Build over them a building} .i.e build a mosque next to them; thus a mosque was built at the entrance of that cave." {Al-Siraaj Al-Muneer, 2/363}. The verse doesn`t include any implication as to whether it is lawful to build a mosque over a grave or not, because the laws of earlier nations don`t apply to us.
Second: The mosque is built over the grave itself and thus the latter became a part of the mosque or its yards, which are set for prayer. This is disliked or forbidden; particularly if the grave is in the direction of Qiblah.
Imam An-Nawawi said: "Citations from Al-Shafie and his fellow scholars are agreed that it is disliked to build a mosque over a grave, whether the dead was righteous or not." {Al-Majmou`, 5/316}.
Moreover, "It is disliked to build a mosque or else over a grave." {Al-Fatawa Al-Hindiah, 1/166}. In addition, "Malik disliked the mosques built over graves" {An-Nawadir Walziyadat}.
Al-Bahwati, a Hanbali scholar, stated, "It is prohibited to build a mosque over graves or amongst them."{Khashaaf al-Khina`,2/141}.
What is prohibited is facing the grave and glorifying it as a Qiblah or as we glorify Allah the Almighty. In fact, doing the latter takes a person out of the fold of Islam, and this is why the Prophet (Blessings and peace be upon him) has prohibited taking graves as places for prayer. We trust that no Muslim would ever think of glorifying a grave equal to Allah or Qiblah. "
Allah cursed the Jews and the Christians because they took the graves of their Prophets as places for praying." Here, the prohibition pertains to worshipping and glorifying the graves. Moreover, "Aisha added, "Had it not been for that, the grave of the Prophet (PBUH) would have been made prominent but I am afraid it might be taken (as a) place for praying..." Al-Muhallab said: "this prohibition is meant to close the means so that the ignorant wouldn`t worship the Prophet`s grave as did the Jews and the Christians with the graves of their prophets." {Shareh Sahih Bukhari By Ibn Battal, 3/311}.
This prohibition is also supported by the following narration, included in Malik`s Muwatt`a, where the Messenger, may Allah bless him and grant him peace, said: "O Allah! Do not make my grave an idol that is worshipped. The anger on those who took the graves of their Prophets as places of prostration was terrible."
However, scholars have permitted building a mosque over an ancient graveyard in which the bones of the deceased have totally decomposed. Ibn Rushd (Grandfather), a Maliki scholar, said: "It isn`t disliked to build a mosque over graves in which the bones of their dwellers have totally decomposed, because both the mosque and the graveyard are endowed for the benefit of the Muslims: the mosque for prayer and the graveyard for burial. However, if the bones of the graveyard`s dwellers have totally decomposed, it isn`t used as burial ground anymore, and there was a need for building a mosque, then that is permissible." {Al-Bayan Watahseel, 2/220}.
In conclusion, there is no sin and it is not disliked to pray at mosques in which there are graves; particularly if the graves are separated from the place of prayer. And Allah the Almighty knows best.