Shaykh Yahya al-Hajooree was asked the following question:
What is the ruling of the hadith “Whoever performs a funeral prayer in a mosque, there is nothing for him (no reward).” (The hadith is) on the authority of Abu Huraira, (and) collected by Abu Dawuud.
This contradicts the authentic hadith in which the Prophet (peace be upon him) performed the janazah prayer on Suhayl ibn Baydah in the masjid. This hadith clearly proves the permissibility of performing a janazah prayer the mosques even though the janazah prayers used to be mainly offered in a mussalla outside the masjid. If it is possible to make a specific place as a musalah for performing the janazah prayers whether it be outside the masjid or a specific area, then this would be the sunnah. But if this is not possible, then it is permissible for them to pray in the masjid and they will be rewarded for their act.”
Taken from aloloom from question and answer sessions with Sheikh Yahya al-hajooree
Abu Aisha Yassin