The Messenger of Allah ﷺ said, "All the earth is a place of prayer and a means of purification, except for graveyards and bathhouses."
حدثنا أحمد بن عبد الملك حدثنا محمد بن سلمة عن محمد بن إسحاق عن عمرو بن يحيى بن عمارة عن أبيه
قال رسول الله ﷺ كل الأرض مسجد وطهور إلا المقبرة والحمام
Its chain of transmission is sahih. Ahmad bin Abdul-Malik bin Waqid Harrani is trustworthy, though he has been criticized without justification, and Muhammad bin Salama, the freed slave of Banu Hashim, is also trustworthy.The hadith was narrated by Abu Dawud, 1/133, no. 492, in the Book of Prayer, chapter on places [of prayer], and by Tirmidhi, 2/131, no. 317, who said, "It contains inconsistency," and by Ibn Majah, 1/246, no. 745, in the Book of Mosques, chapter on the places where prayer is disliked, and by Darimi, 1/375, no. 1390, and by Ibn Hibban, 104, no. 338. Hakim graded it sahih, 1/251, and Dhahabi agreed with him.