The correct position is that of the first group, for the reports concerning graveyards and bathhouses constitute an explicit specification of the general permission to pray wherever one is overtaken by the time of prayer.
Scholars have differed over the reason why prayer is prohibited in a bathhouse. Some said it is because filth is abundant there; others held that it is because such places are the abode of devils. Al-Nawawī judged the latter view to be the sounder opinion—and Allah knows best.
Fifth: Every place frequented by Satan is likewise disapproved for prayer, such as venues of debauchery and flagrant sin, and buildings used for Christian or Jewish worship—churches and synagogues, for example. The evidence is the Prophet’s statement, when he and his Companions halted on a journey and overslept the dawn prayer: “Let each man take hold of his mount’s head, for this is a spot where Satan was present among us.” He therefore did not pray there.
The report is narrated by Abū Hurayrah, who said: “We camped with the Messenger of Allah ﷺ and did not wake up until the sun had risen. The Prophet ﷺ then said…”—and he related the incident—“so we did as he instructed. He then called for water, performed ablution, prostrated twice, the call to prayer was given, and he performed the dawn prayer.” Narrated by Muslim and al-Bayhaqī.
This story is also transmitted in fuller detail by Abū Qatādah and other Companions, but their versions do not contain the wording that forms the point of evidence here; the full discussion has already appeared under the chapter on prayer times.
Al-Nawawī states in al-Majmūʿ: “Praying in a place frequented by Satan is unanimously deemed disliked, such as establishments where wine is served, taverns, collection points for illicit taxes, and other sites of blatant disobedience—as well as churches and synagogues.”