Answered by Shaykh Ubayd al Jabiree in Telelink for Sri Lanka:
The original question was if the masjid has a qabr or a grave is it permissible to pray in it. So Shaykh Ubayd (hafidhahullah) he went on after praising Allaah and saying peace and blessings on the Messenger and his family and companions, he went on to say in regards to this question that there are basically two situations.
The first of them is that, if the grave came before the masjid, and the masjid was built because of the grave being there and was built so that the people would worship the person who was in that grave, worshipping besides Allaah. And the Shaykh goes on to mention that there is a severe threat in regards to this affair. And he went on to mention some of the nusoos, some of the texts in regards to that, like the saying of the Messenger (sallalhualahi wa sallam) that the anger of Allaah is upon the people who take the graves of the Prophets as masaajids.
And in another narration, that the Prophet (sallalhualahi wa sallam) asked for curse of Allaah to be upon the Jews and Christians, because they took the graves of their Prophets as Masaajids.
So the Shaykh went on to say that there are many hadith on this issue. So he said in regards to this, that it is not allowed to pray in it, because this masjid was built, because of the grave, because it was built, to worship other than Allaah. So the Shaykh said in this situation, then it is not allowed to pray in the masjid.
Then the Shaykh mentioned a second situation and that is, if the masjid is built and the grave is built inside the masjid intentionally.
So the Shaykh went on to mention that there are two things that can be done in this case.
Then one of them, that a wall or separation is built to separate the grave from the masjid; or the second situation that the grave is taken out of the masjid and the person who was in the grave and buried along with the other Muslims.
So then the Shaykh was asked, what is the case if the grave remains inside and not separate from the masjid, then the Shaykh said then it is not allowed to pray in it. It is not allowed to pray in this masjid.
Posted from: http://www.uthmaanlk.org/?page_id=143