The Messenger of Allah ﷺ said, "The whole earth is a place of prayer, except for graveyards and bathrooms."
حدثنا محمد بن يحيى حدثنا يزيد بن هارون قال حدثنا سفيان عن عمرو بن يحيى عن أبيه وحماد بن سلمة عن عمرو بن يحيى عن أبيه
قال رسول الله ﷺ الأرض كلها مسجد إلا المقبرة والحمام
Its isnad is sahih. Abu Dawud narrated it in the Book of Prayer, the chapter on the places where prayer is not permitted, hadith no. 492. Tirmidhi mentioned it in a suspended form, narrating it from Hammad, and Ibn Khuzayma, Ibn Hibban, Hakim, and Dhahabi graded it sahih.