The Messenger of Allah ﷺ said, "The whole earth is a place of prayer, except for graveyards and bathrooms."
حدثنا ابن أبي عمر وأبو عمار الحسين بن حريث المروزي قالا حدثنا عبد العزيز بن محمد عن عمرو بن يحيى عن أبيه
قال رسول الله ﷺ الأرض كلها مسجد إلا المقبرة والحمام
Its isnad is sahih. Ibn Majah, no. 745, and Abu Dawud, no. 492, also reported it from the hadith of Amr bin Yahya with the same wording. Ibn Khuzayma graded it sahih, no. 791, as did Ibn Hibban, no. 338, 339, and Hakim, 1/251, saying it meets the standard of the two Shaykhs, and Dhahabi agreed.There are also reports on this subject from Ali [Ahmad, 1/58, 98, and Bazzar (Kashf), 3/147, no. 2443], Abdullah bin Amr [Ahmad, 2/222], Abu Hurairah [coming up, no. 1553], Jabir [2/222, Bukhari, no. 335, 438, and Muslim, no. 521], Ibn Abbas [Ahmad, 1/250, 301], Huzaifa [Muslim, no. 522], Anas [Sarraj in his Musnad, manuscript, p. 48a, with a sahih chain of transmission], Abu Umama [coming up, no. 1553, and Ahmad, 5/248, 256], and Abu Dharr [Muslim, no. 520, and Bukhari, no. 3366].