Question 61: offering Salaah (prayer) in a Masjid (mosque) with a grave inside it. Some scholars say that it is impermissible to pray there and if there is no other Masjid in town, it is better to pray at home than in a Masjid with a grave inside it. Other scholars say that it is permissible to pray there, because the grave of the Messenger of Allaah (peace be upon him) is inside his Masjid, as well as the graves of his two Companions, ‘Aboo Bakr and ‘Umar. This matter seems confusing to me, so I wrote this letter to inquire about the truth. I live in the countryside of Senegal where there is only one Masjid in our town in which there are four graves. Three of them are outside the Masjid, but they are adjacent to its southern part, whereas the fourth is completely inside the Masjid. Please inform me of the truth supported by evidence, as I know nothing about this matter, therefore I am asking you, for Allaah says in His Glorious Book (what means): So ask the people of the Scripture, if you do not know. (Soorah Al-Nahl, 16: 43).
Answer: First, it is impermissible to build Masjids over graves, or offer Salaah in a Masjid that was built over a grave or graves, as it is authentically established that Lady `Aa’ishah (may Allah be pleased with her) said, “When death came upon the Messenger of Allaah (peace be upon him), he started to cast a garment of his over his face, and when it made him short of breath, he would remove it from his face; while in that state he said, ‘May the Curse of Allaah be upon the Jews and the Christians; for they have taken the graves of their Prophets as places of worship.’” (‘Aa’ishah said), “He was warning against (doing) what they did.” She also said, “Had it not been for that, his grave would have been made prominent, but he feared lest it might be taken as a place of worship.” Narrated by Al-Bukhaaree and Muslim. Jundub ibn ‘Abdullaah (may Allaah be pleased with him) also narrated that he heard the Prophet (peace be upon him), five days before his death, saying… read more here.