Question 318: If there is a grave in the backyard of a Masjid (mosque) with a wall in between, is it permissible to perform Salaah in that Masjid? Is performing Salaah there valid or not? What is the legal ruling on a person who swears by other than Allaah such as the Prophet or Al-Amaanah (Honesty)?
Answer: It is invalid to offer Salaah in any Masjid where there is a grave. The Prophet (peace be upon him) is quoted to have prohibited to take graves as Masjids. The prohibition indicates that it is not permissible to perform Salaah there whether a building was established upon it or not, or if the grave is attached and connected directly to the Masjid or the Masjid is built for its sake. However, in case the Masjid is separated from the grave with a street or a passage for example, there will be no harm to pray therein. It is not permissible to swear by other than Allaah (Glorified be He), neither by the Prophet (peace be upon him) or anyone else because the Prophet stated: Anyone who swears by other than Allaah has committed a disbelief or has associated others with Allaah.... read more here.