The Messenger of Allah ﷺ said, "The whole earth is a place of prayer, except for the bathhouse and the graveyard."
قال رسول الله ﷺ: الأرض كلها مسجد إلا الحمام والمقبرة.
It was narrated by Abu Dawud (492) and Ibn Majah (745), both through Hammad bin Salama, from Amr bin Yahya bin Umara, from his father, from Abu Saeed Khudri, who related the hadith. It was likewise narrated by Ahmad (11788) from Hammad bin Salama as connected. Abdul-Wahid bin Ziyad followed him in narrating it as connected, relating it from Amr bin Yahya in the same manner.It was narrated by Abu Dawud (492), Ibn Khuzayma (791) and Ibn Hibban (1199) in their two Sahihs, Hakim (1/251), Bayhaqi (2/435), and Ahmad (11919). Abdul-Aziz bin Muhammad Darawardi also followed them in narrating it as connected, relating it from Amr bin Yahya in the same manner.It was narrated by Tirmidhi (317), Ibn Khuzayma (791), Hakim (1/251), and Darimi in his Sunan (1396). Muhammad bin Ishaq followed all of them, narrating it from Amr bin Yahya in the same manner. It was narrated by Imam Ahmad (11684), except that Muhammad bin Ishaq is a mudallis and he narrated it using "an," but he was corroborated as mentioned above.The hadith has another route, narrated by Hakim, and from him Bayhaqi, through Umara bin Ghaziya, from Yahya bin Umara Ansari, from Abu Saeed Khudri, in the same manner. Hakim said, "All these chains are sahih according to the standard of Bukhari and Muslim." This was after he narrated it through this route, and through the routes of Abdul-Wahid and Darawardi.Through these chains this hadith is confirmed as sahih, and it is not undermined by the narration of Sufyan Thawri as mursal, as Tirmidhi said, "Sufyan Thawri narrated it, from Amr bin Yahya, from his father, from the Prophet ﷺ, as mursal." He then mentioned the narration of Hammad bin Salama and Muhammad bin Ishaq, then said, "It seems that the narration of Thawri, from Amr bin Yahya, from his father, from the Prophet ﷺ, is more firmly established and more sahih."This is what Tirmidhi, may Allah have mercy on him, said, and Bayhaqi followed him in this, saying, "The hadith of Thawri is mursal, and it has been narrated as connected, but that is nothing."I say, there is room for question in this statement, for an addition from a reliable narrator is accepted according to the majority of the people of hadith. The fact that Sufyan Thawri narrated it as mursal does not harm the position of whoever narrated it as connected.Ibn Daqiq Eid said in Al-Imam, "The gist of what has been used to fault it is the claim of disconnection, and when the one who raises the chain to a connected form is reliable, it is accepted." Nasb Raya (2/324).Sheikh Islam Ibn Taymiya also declared it sahih, saying, "Whoever has criticized it has not fully examined its routes." Iqtida Sirat Mustaqim (2/672). He also said, "The scholars of hadith have declared it sahih, and they have clarified that the narration of the one who related it as mursal does not contradict the established connected narration." Majmu Fatawa (21/320).For further reference, see Sheikh Islam Ibn Taymiya wa Juhuduhu fil-Hadith wa Ulumih (3/357).