Source: “Ahkam wa Masail in the Light of the Qur’an and Hadith”, Volume 02
Referenced from: Fatawa Thanaiyyah, Volume 1, Page 321
As-Salāmu ʿAlaikum wa Rahmatullāhi wa Barakātuh
Is it permissible to construct a mosque within a graveyard out of necessity?
The Messenger of Allah ﷺ has strictly prohibited performing prayers in graveyards, and therefore, there is no justification for constructing a mosque in such a location.
In fact, the Prophet ﷺ cursed those who build mosques over graves. This is evident from the following Hadith:
قال رسول اللّٰه صلى الله عليه وسلم:
«لَعَنَ اللّٰهُ الْيَهُودَ وَالنَّصَارَى اتَّخَذُوا قُبُورَ أَنْبِيَائِهِمْ مَسَاجِدَ»
“Allah cursed the Jews and Christians who took the graves of their prophets as places of worship.”
— (Ṣaḥīḥ al-Bukhārī & Ṣaḥīḥ Muslim)
This Hadith makes it explicitly clear that building mosques within or over graveyards is a condemned act and subject to divine curse, as it is a practice of previous nations that was prohibited in Islam.
Thus, constructing a mosque in a graveyard is not permissible, and those who do so fall under the condemnation mentioned in the Hadith.
والله تعالى أعلم بالصواب
And Allah, the Exalted, knows best what is correct.

❖ Question:
As-Salāmu ʿAlaikum wa Rahmatullāhi wa Barakātuh
Is it permissible to construct a mosque within a graveyard out of necessity?
❖ Answer:
The Messenger of Allah ﷺ has strictly prohibited performing prayers in graveyards, and therefore, there is no justification for constructing a mosque in such a location.
In fact, the Prophet ﷺ cursed those who build mosques over graves. This is evident from the following Hadith:
قال رسول اللّٰه صلى الله عليه وسلم:
«لَعَنَ اللّٰهُ الْيَهُودَ وَالنَّصَارَى اتَّخَذُوا قُبُورَ أَنْبِيَائِهِمْ مَسَاجِدَ»
“Allah cursed the Jews and Christians who took the graves of their prophets as places of worship.”
— (Ṣaḥīḥ al-Bukhārī & Ṣaḥīḥ Muslim)
This Hadith makes it explicitly clear that building mosques within or over graveyards is a condemned act and subject to divine curse, as it is a practice of previous nations that was prohibited in Islam.
Thus, constructing a mosque in a graveyard is not permissible, and those who do so fall under the condemnation mentioned in the Hadith.
والله تعالى أعلم بالصواب
And Allah, the Exalted, knows best what is correct.