Answer
(Fatwa: 1257/1147=L/1429)
According to Hanafi Fiqh, funeral prayer is undesirable in a mosque, but other Imams allow it. The Hanafi Fiqh present the Hadith as proof:
من صلى على جنازة فى المسجد فلا شئ له (ابو داود)
It means that the person who will offer funeral prayer in a mosque, there is nothing for him i.e. he will get no reward.
Also, at the time of the Prophet (صلى الله عليه وسلم), funeral prayer was being performed out of mosques. Ibn Habib says that in Madinah, the place for offering funeral prayer was eastward adjacent to the Masjid Nnabvi. (Fat-hul
وموضع الجنازة بالمدينة خارج المسجد وهو الموضع الذي كان النبي صلى الله عليه وسلم يصلى على الجنازة فيه
The place to perform funeral prayer in Madinah is out of mosque, and this was the place where the Prophet (صلى الله عليه وسلم) offered funeral prayers (Muatta Imam Muhammad).
Allah (Subhana Wa Ta’ala) knows Best
Darul Ifta,
Darul Uloom Deoband