Graves and Mosques (Hadith No. 1113)
Aisha said, “The Prophet in his fatal illness said, ‘Allah cursed the Jews and the Christians because they took the graves of their Prophets as places for praying.”‘ Aisha added, “Had it not been for that the grave of the Prophet (p.b.u.h) would have been made prominent but I am afraid it might be taken (as a) place for praying.
The scholars have discussed this issue, in the past and more recently, and they refuted those who quote the fact that the grave of the Prophet (peace and blessings of Allaah be upon him) is inside his mosque as evidence that it is permissible to take graves as places of worship, or to include graves in mosques.
Shaykh ‘Abd al-‘Azeez ibn Baaz (may Allaah have mercy on him) said:
There is a specious argument put forward by those who worship graves, namely the fact that the grave of the Prophet (peace and blessings of Allaah be upon him) is in his mosque. The answer to that is that the Sahaabah (may Allaah be pleased with them) did not bury him in his mosque, rather they buried him in the house of ‘Aa’ishah (may Allaah be pleased with her). When al-Waleed ibn ‘Abd al-Malik expanded the Mosque of the Prophet (peace and blessings of Allaah be upon him) at the end of the first century, he incorporated the room into the mosque, but he did wrong thereby, and some of the scholars denounced him for that, but he believed that there was nothing wrong with it for the sake of expanding the mosque.
It is not permissible for a Muslim to take that as evidence that mosques may be built over graves, or that people may be buried inside mosques, because that goes against the saheeh ahaadeeth, and because it is a means that may lead to shirk by associating the occupants of the graves in worship with Allaah. End quote.
Majmoo’ Fataawa al-Shaykh Ibn Baaz, 5/388, 389.
[Taken from IslamQA]
Read more here.