This excerpt is taken from Sheikh Ghulam Mustafa Zaheer Amanpuri's book The Shariah Status of Blessings.
Building mosques on graves is unanimously considered forbidden and prohibited. Consider the statements of the scholars:
[1] Imam Shafi'i, may Allah have mercy on him (204 AH)
He considered building a mosque on a grave, or praying on or facing it, to be disliked.
Reference: (Al-Umm: 278/1)
[2] Sheikh al-Islam Ibn Taymiyyah, may Allah have mercy on him (728 AH), says:
[قال علماؤنا : لا يجوز بناء المساجد على القبور، وقالوا: إنه لا يجوز أن ينذر لقبر، ولا للمجاورين عند القبر شيئا من الأشياء، لا من درهم، ولا من زيت، ولا من شمع، ولا من حيوان، ولا غير ذٰلك، كله نذر معصية]
The scholars of Islam say that building mosques on graves is not permissible. They also say that offering anything, such as dirhams and dinars, oil, candles, animals, etc., as a vow for any grave or the visitors sitting there is not permissible, because all these vows are based on disobedience to Allah Almighty.
Reference: (Majmoo' al-Fatawa: 77/27)
[3] Hafiz Suyuti, may Allah have mercy on him (died 911 AH), says:
[أما بناء المساجد عليها، وإشعال القناديل والشموع أو السرج عندها؛ فقد لعن فاعله ......، وصرح عامة علماء الطوائف بالنهي عن ذٰلك متابعة للأحاديث الواردة في النهي عن ذٰلك، ولا ريب في القطع بتحريمه]
Cursing has been prescribed for those who build mosques on graves and light lanterns and candles there. ...... Most scholars of various schools of thought have clearly prohibited this, following the ahadith based on its prohibition. There is no doubt in declaring this act absolutely forbidden.
Reference: (الأمر بالاتباع، ص 59-60)
They also say:
[هٰذه المساجد المبنية على القبور يتعين إزالتها، هٰذا مما لا خلاف فيه بين العلماء المعروفين، وتكره الصلاة فيها من غير خلاف]
It is agreed upon by well-known scholars that it is necessary to demolish mosques built on graves, and also unanimously disliked to pray there.
Reference: الأمر بالاتباع، ص 115، وفي نسخة، ص 61
[4] Hafiz Nawawi, may Allah have mercy on him (676 AH), says:
[اتفقت نصوص الشافعي والأصحاب على كراهة بناء مسجد على القبر، سواء كان الميت مشهورا بالصلاح، أو غيره، لعموم الأحاديث]
Imam Shafi'i, may Allah have mercy on him, and his companions agree in their fatwas that building a mosque on a grave is disliked. Considering the generality of the hadith, whether the deceased is righteous or wicked, it is the same in this matter.
Reference: (المجموع شرح المهذّب: 316/5)
A question was posed to Hafiz Nawawi, may Allah have mercy on him, and in answering it he says:
[مسألة: مقبرة مسبلة للمسلمين، بنى إنسان فيها مسجدا، وجعل فيها محرابا، هل يجوز ذٰلك؟ وهل يجب هدمه؟
الجواب: لا يجوز له ذٰلك، ويجب هدمه]
Question: If a person builds a mosque and a mihrab in a public cemetery dedicated to Muslims, is this permissible? Also, is it obligatory to demolish it?
Answer: It is not permissible to do so, and it is obligatory to demolish it.
Reference: (Fatawa al-Nawawi, p. 65)
Further states:
[قال الشافعي في الأم: ورأيت الأئمة بمكة يأمرون بهدم ما يبنى، ويؤيد الهدم قوله: ولا قبرا مشرفا؛ إلا سويته]
Imam Shafi'i, may Allah have mercy on him, said in Kitab al-Um: I saw the Imams in Makkah ordering the demolition of (structures built on graves), and the demolition is supported by the Prophet’s ﷺ command to level every elevated grave.
Reference: Sharh Muslim: 27/7
[5] Allama Barkawi Hanafi, may Allah have mercy on him (981 AH), states:
[قد صرح عامة الطوائف بالنهي عن بناء المساجد عليها، والصلاة إليها]
Most Islamic schools of thought have explicitly prohibited building mosques on graves and praying facing them.
Reference: (Ziyarat al-Qubur, p. 4)
[6] Allama Ibn Abidin Shami, may Allah have mercy on him (1252 AH), states:
[أما البناء عليه؛ فلم أر من اختار جوازه]
I do not know of any scholar who considers building a structure on a grave permissible.
Reference: Hashiyat Ibn Abidin: 601/1
[7] Hafiz Ibn Abd al-Barr, may Allah have mercy on him (463 AH)
They argue from the Hadith of Aisha (may Allah be pleased with her):
[هٰذا يحرم على المسلمين أن يتخذوا قبور الأنبياء والعلماء والصالحين مساجد]
This Hadith prohibits Muslims from making the graves of the Prophets, scholars, and righteous people places of prostration.
Reference: (Al-Tamhid: 186/1)
[8] Allama Abu Abdullah Al-Qurtubi (may Allah have mercy on him) (671 AH) states in the Tafsir of Surah Al-Kahf:
[اتخاذ المساجد على القبور، والصلاة فيها، والبناء عليها، إلى غير ذٰلك، مما تضمنته السنة من النهي عنه؛ ممنوع لا يجوز]
Building mosques on graves, praying in them, constructing buildings over them, and other matters prohibited by the Sunnah are forbidden and unlawful.
Reference: (Tafsir Al-Qurtubi: 379/1)
He also states:
[أما تعلية البناء الكثير علىٰ نحو ما كانت الجاهلية تفعله تفخيما وتعظيما؛ فذٰلك يهدم ويزال، فإن فيه استعمال زينة الدنيا في أول منازل الآخرة، وتشبها بمن كان يعظم القبور ويعبدها، وباعتبار هٰذه المعاني وظاهر النهي أن ينبغي أن يقال: هو حرام]
As for raising buildings over graves to honor and venerate them like the people of ignorance, they should be demolished and removed, because this uses the adornment of this world in the very first abode of the Hereafter. Moreover, it necessarily leads to resembling those who venerate and worship graves. Considering these meanings and the apparent prohibition, it is necessary to declare it forbidden.
Reference: Tafsir Al-Qurtubi: 381/10
He also states:
[قال علماؤنا: وهٰذا يحرم على المسلمين أن يتخذوا قبور الأنبياء والعلماء مساجد]
The scholars of Islam have said that these evidences make it unlawful for Muslims to build mosques on the graves of the Prophets and scholars.
Reference: (Tafsir Al-Qurtubi: 380/1)
[9] Sheikh al-Islam Ibn Taymiyyah, may Allah have mercy on him (728 AH), says:
[هٰذه المساجد المبنية علىٰ قبور الأنبياء، والصالحين، والملوك وغيرهم، يتعين إزالتها بهدم أو بغيره، هٰذا مما لا أعلم فيه خلافا بين العلماء المعروفين، وتكره الصلاة فيها من غير خلاف أعلمه، ولا تصح عندنا في ظاهر المذهب لأجل النهي واللعن الوارد في ذٰلك، ولأحاديث أخر]
It is necessary to demolish or otherwise remove those mosques built over the graves of the noble Prophets, righteous people, and kings, etc. To my knowledge, there is no disagreement among the well-known scholars on this matter. Without any doubt, praying in these mosques is also disliked. Based on this hadith and other hadiths mentioning prohibition and curse, our apparent religious stance is that doing so is impermissible.
Reference: Iqtidāʼ aṣ-Ṣirāṭ al-Mustaqīm : 287/2
He also says:
[اتفق الأئمة أنه لا يبنىٰ مسجد علىٰ قبر، لأن النبي صلى الله عليه وسلم قال: «إن من كان قبلكم كانوا يتخذون القبور مساجد، ألا فلا تتخذوا القبور مساجد، فإني أنهاكم عن ذٰلك»، وأنه لا يجوز دفن ميت في مسجد، فإن كان المسجد قبل الدفن غير، إما بتسوية القبر، وإما بنبشه إن كان جديدا، وإن كان المسجد بني بعد القبر، فإما أن يزال المسجد، وإما أن تزال صورة القبر، فالمسجد الذي على القبر؛ لا يصلىٰ فيه فرض ولا نفل، فإنه منهي عنه]
The consensus of the Imams is that a mosque should not be built over a grave, because the Holy Prophet ﷺ said: People before you used to build mosques over graves, beware, do not make graves places of prostration, I forbid you from this. Similarly, it is not permissible to bury a deceased in a mosque; if the mosque was built before the burial, then the grave should be leveled, or if the grave is new, it should be removed. If the mosque was built later, then in such a case either the mosque should be demolished, or the grave should be removed. It is forbidden to perform any obligatory or voluntary prayers in a mosque built over a grave.
Reference: Majmu' al-Fatawa: 194/22-195
He also says:
[المقصود هاهنا أن الصحابة والتابعين لهم بإحسان لم يبنوا قط علىٰ قبر نبي ولا رجل صالح مسجدا، ولا جعلوه مشهدا ومزارا، ولا علىٰ شيء من آثار الأنبياء، مثل مكان نزل فيه أو صلىٰ فيه، أو فعل فيه شيئا من ذٰلك، لم يكونوا يقصدون بناء مسجد لأجل آثار الأنبياء والصالحين]
In short, the Companions and the Followers never built a mosque over the grave of any prophet or any righteous person, nor did they turn any grave into a shrine or a court. They did not intend to build a mosque based on the traces of the Prophets, such as the place where the Prophet Muhammad ﷺ stayed, prayed, or performed any other act, due to the traces of the Prophets and the righteous.
Reference: Majmoo' al-Fatawa: 466/17
He also states:
[هٰذه المساجد المبنية علىٰ قبور الأنبياء، والصالحين، والملوك وغيرهم، يتعين إزالتها بهدم أو بغيره، هٰذا مما لا أعلم فيه خلافا بين العلماء المعروفين، وتكره الصلاة فيها من غير خلاف أعلمه]
It is necessary to demolish or otherwise remove mosques built over the graves of Prophets, righteous people, kings, etc. I am not aware of any disagreement among the well-known scholars on this issue. Also, it is unanimously disliked to perform prayers in such mosques.
Reference: Iqtidāʼ al-Ṣirāṭ al-Mustaqīm: 187/2
At one place he says:
[والنصارى كثيرا ما يعظمون آثار القديسين منهم. فلا يستبعد أنهم ألقوا إلى بعض جهال المسلمين أن هذا قبر بعض من يعظمه المسلمون ليوافقوهم على تعظيمه. كيف لا؟ وهم قد أضلوا كثيرا من جهال المسلمين حتى صاروا يعمدون أولادهم ويزعمون أن ذلك يوجب طول العمر للولد وحتى جعلوهم يزورون ما يعظمونه من الكنائس والبيع وصار كثير من جهال المسلمين ينذرون للمواضع التي يعظمها النصارى كما قد صار كثير من جهالهم يزورون كنائس النصارى ويلتمسون البركة من قسيسيهم ورهابينهم ونحوهم. والذين يعظمون القبور والمشاهد: لهم شبه شديد بالنصارى حتى إني لما قدمت القاهرة اجتمع بي بعض معظميهم من الرهبان وناظرني في المسيح ودين النصارى حتى بينت له فساد ذلك وأجبته عما يدعيه من الحجة وبلغني بعد ذلك أنه صنف كتابا في الرد على المسلمين وإبطال نبوة محمد صلى الله عليه وسلم وأحضره إلي بعض المسلمين وجعل يقرؤه علي لأجيب عن حجج النصارى وأبين فسادها. وكان من أواخر ما خاطبت به النصراني: أن قلت له: أنتم مشركون وبينت من شركهم ما هم عليه من العكوف على التماثيل والقبور وعبادتها والاستغاثة بها. قال لي: نحن ما نشرك بهم ولا نعبدهم وإنما نتوسل بهم كما يفعل المسلمون إذا جاءوا إلى قبر الرجل الصالح فيتعلقون بالشباك الذي عليه ونحو ذلك. فقلت له: وهذا أيضا من الشرك ليس هذا من دين المسلمين وإن فعله الجهال فأقر أنه شرك حتى إن قسيسا كان حاضرا في هذه المسألة. فلما سمعها قال: نعم على هذا التقدير نحن مشركون. وكان بعض النصارى يقول لبعض المسلمين: لنا سيد وسيدة ولكم سيد وسيدة لنا السيد المسيح والسيدة مريم ولكم السيد الحسين والسيدة نفيسة. فالنصارى يفرحون بما يفعله أهل البدع والجهل من المسلمين مما يوافق دينهم ويشابهونهم فيه ويحبون أن يقوى ذلك ويكثر ويحبون أن يجعلوا رهبانهم مثل عباد المسلمين وقسيسيهم مثل علماء المسلمين. ويضاهئون المسلمين فإن عقلاءهم لا ينكرون صحة دين الإسلام. بل يقولون: هذا طريق إلى الله وهذا طريق إلى الله. ولهذا يسهل إظهار الإسلام على كثير من المنافقين الذين أسلموا منهم. فإن عندهم أن المسلمين والنصارى كأهل المذاهب من المسلمين بل يسمون الملل مذاهب.]
The Christians often hold the graves of their saints and God-fearing elders in the highest reverence. It is not unlikely that they have instilled in the minds of some ignorant Muslims the idea that this grave belongs to a saint greatly respected by Muslims, so that Muslims might also align with Christians in venerating graves. How could this be unlikely? Christians have misled many ignorant Muslims to such an extent that even ignorant Muslims, like Christians, perform 'baptism' (the sprinkling of holy water in Christianity) on their children, believing it prolongs the child's life. Christians have misled Muslims so much that ignorant Muslims have begun to visit and venerate the places of worship of Jews and Christians. Many ignorant Muslims have started offering vows and sacrifices at the places venerated by Christians. It has come to the point where some ignorant Muslims visit Christian churches and seek blessings from their priests and Sufis, etc. Those who venerate graves and shrines bear a great resemblance to Christians. When I came to Cairo, a prominent Christian monk approached me and began debating with me about Prophet Jesus (peace be upon him) and the Christian religion. I clarified the faults of mainstream Christianity and answered all his arguments. Later, I learned that they had written a book refuting Islam and the prophethood of the Holy Prophet ﷺ. A Muslim brought that book to me and started reading it in front of me so that I could respond to the Christian arguments and expose their faults. In the final debate with that Christian monk, I said: You are polytheists. I explained their polytheism by saying: You are worshippers of graves, idolaters, worshippers of graves, and those who seek help from them. Upon hearing this, he said: We neither associate partners with those elders nor worship them; rather, we use them as intermediaries, just as Muslims use deceased persons as intermediaries. Also, Muslims visit the graves of righteous people, cling to their windows, and perform similar acts. I told him: All this is polytheism and has no connection with Islam, although some ignorant people do these things. He admitted that this is polytheism. Even a Christian priest present there said: Yes! On this basis, we are indeed polytheists. Some Christians tell Muslims: We also have a Sayyid and a Sayyida, and you also have a Sayyid and a Sayyida. Our Sayyid is Jesus Christ (peace be upon him) and Sayyida Maryam (may Allah be pleased with her), while yours are Sayyid Hussain (may Allah be pleased with him) and Sayyida Nafisa (may Allah be pleased with her). Christians are very pleased with the polytheistic and innovative acts of ignorant and heretical Muslims because these resemble their religion. They want these acts to become stronger and more widespread among Muslims. They wish their monks to become like the courtiers of Muslims and their priests to become like Muslim scholars, thus making them resemble Muslims. The intellectuals among Christians do not deny the truth of Islam; rather, they say that Christianity is also a path to Allah Almighty, and Islam is also a path. Therefore, for many of them, expressing Islam has become easy because, in their view, Islam and Christianity are like the various sects among Muslims, meaning they have started calling nations sects.
Reference: Majmoo' al-Fatawa: 460/27-462
[10] Allama Ibn Qayyim, may Allah have mercy on him (751 AH), says:
[من الأنصاب ما قد نصبه الشيطان للمشركين؛ من شجرة، أو عمود، أو وثن، أو قبر، أو خشبة، أو غير ذٰلك، والواجب هدم ذٰلك كله، ومحو أثره، كما أمر النبي صلى الله تعالىٰ عليه وآله وسلم عليا رضي الله عنه بهدم القبور المشرفة، وتسويتها بالأرض]
It is necessary to demolish all the idols that Satan has established for the polytheists in the form of trees, pillars, posts, graves, or wooden objects, and to erase their traces, just as the Prophet Muhammad ﷺ ordered Sayyiduna Ali, may Allah be pleased with him, to demolish elevated graves and level them with the ground.
Reference: Ighathat al-Lahfan min Masaid al-Shaytan: 209/1
[11] Allama Ibn al-Hajj, may Allah have mercy on him (737 AH), says:
[هٰذا إجماع من هٰؤلاء العلماء المتأخرين، فكيف يجوز البناء فيها؟ فعلىٰ هٰذا؛ فكل من فعل ذٰلك، فقد خالفهم]
There is consensus among the later scholars on demolishing solid and elevated graves. In this case, how can it be permissible to build domes or the like over graves? Therefore, whoever does so will be opposing those scholars.
Reference: (Al-Madkhal: 182/1, and in one copy: 253/1)
[12] It is written in a reliable book of the Hanafis:
[يكره أن يبنىٰ على القبر مسجد أو غيره، كذا في السراج الوهاج، ويكره عند القبر ما لم يعهد من السنة، والمعهود منها ليس إلا زيارته والدعاء عنده قائما، كذا في البحر الرائق]
Building a mosque or any other structure over a grave is disliked. This is also mentioned in Al-Siraj Al-Wahhaj. Additionally, performing actions near the grave that are not proven by Sunnah is also disliked. The only Sunnah established is to visit the grave and stand by it to pray for the owner of the grave. This is written in Al-Bahr Al-Ra’iq as well.
Reference: Fatawa Alamgiri: 166/1
[13] Allama Alusi, may Allah have mercy on him, has narrated from Allama Ibn Hajar Haytami, may Allah have mercy on him (974 AH):
[قد أفتىٰ جمع بهدم كل ما بقرافة مصر من الأبنية، حتىٰ قبة الإمام الشافعي عليه الرحمة، التي بناها بعض الملوك، وينبغي لكل أحد هدم ذٰلك ما لم يخش منه مفسدة، فيتعين الرفع للإمام أخذا من كلام ابن الرفعة في الصلح]
In the cemeteries of Egypt, all the structures built over graves, even the dome built by some kings over the grave of Imam Shafi’i, the large group of scholars have issued a fatwa to demolish all of them. If there is no fear of fitnah and disorder, it is obligatory for everyone to demolish them. It is necessary to raise this matter before the ruler, as is understood from the words of Ibn Rafi’ah in the chapter of reconciliation.
Reference: Ruh Al-Ma’ani: 226/8