It is narrated from Yahya al-Mazni that the Messenger of Allah ﷺ said: "All the earth is a mosque except for bathhouses and graveyards." Imam Shafi'i, may Allah have mercy on him, says: I have found this hadith in two places in my book, in one place as mursal (disconnected) and in another place narrated from Abu Sa'id al-Khudri, may Allah be pleased with him. He reports it from the Prophet ﷺ.
Hadith Referenceمسند الإمام الشافعي / كتاب الصلاة / 174
Hadith Takhrijاخرجه ابو داود الصلاة، باب في المواضع التي لا تجوز فيها الصلوة: 492 - وابن ماجة، المساجد، باب المواضع التي تكره فيها الصلاة: 745 - والترمذى، الصلاة، باب ماجاء ان لارض كلها مسجد إلا المقبرة والحمام: 317- وصححه ابن خزيمة: (791، 792) - والحاكم على شرط الشيخين: 1/ 251.