Question
As-salamu alaykum wa rahmatullahi wa barakatuh
Is it permissible or not to build a mosque in a graveyard when there is a need?
Answer
The Messenger of Allah ﷺ forbade praying in a graveyard, so there is no need for a mosque there; rather, he cursed the one who builds a mosque in a graveyard.
قال رسول اللّٰه صلى الله عليه وسلم: «لعن اللّٰه اليهود والنصاريٰ اتخذوا قبور انبياء هم مساجد» (الحديث)
Reference: (Fatawa Thanaiyyah, Volume 1, p. 321)