The evidence for this is the hadith of Aishah, may Allah be pleased with her: “The Prophet, may Allah’s peace and blessings be upon him, offered the funeral prayer over Sahl ibn Bayda in the mosque.” (1) Although the Messenger, may Allah’s peace and blessings be upon him, had a designated prayer-place for funerals, he would sometimes offer the funeral prayer in the mosque.
If someone were to ask: According to the view that it is disliked, where should the funeral prayer be offered?
The answer is: A place should be designated specifically for funeral prayers, as is customary in many Muslim lands. It should be near the cemetery, since that is easier for those accompanying the funeral. For instance, if people gather in a mosque within the town, this creates inconvenience: they will all have to proceed with the funeral, and the cemetery may be far away. But if the funeral prayer-place is near the cemetery, people can come in groups from their homes to that place, offer the prayer over the deceased, and then proceed to the cemetery without difficulty.
In Najd, where we are, they do not designate a special place for funeral prayers; rather, the deceased are brought to the mosques. Since there is no harm in this, we do not forbid it, nor do we say that the deceased might cause harm to the mosque—unless there is a particular circumstance, such as when the deceased died in an accident and blood is still flowing from him. In that case, we prevent the funeral prayer from being offered over him in the mosque, because he would soil it.