The Messenger of Allah ﷺ said, "Whoever performs the funeral prayer over a deceased person in the mosque receives no reward for it."
حدثنا علي بن محمد حدثنا وكيع عن ابن أبي ذئب عن صالح مولى التوأمة
قال رسول الله ﷺ من صلى على جنازة في المسجد فليس له شيء
[Its isnad is hasan] Reported by Abu Dawud, Funerals, chapter on the funeral prayer in the masjid, no. 3191, from the hadith of Ibn Abu Dhib with this chain. Ibn Qayyim graded it hasan, and I have not seen any valid argument from those who weakened it.Bayhaqi reported, 4/52, from Salih, "I saw the funeral bier placed in the masjid, and I saw that when Abu Hurairah could not find a place except in the masjid, he would leave and not pray over it."And in the narration of Tayalisi, 2310, from Ibn Abu Dhib, from Salih, he said, "I met men among those who had met the Prophet ﷺ and Abu Bakr, and when they came and could not find anywhere to pray except in the masjid, they would turn back and not pray."