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.
It is narrated from Abdullah bin Ma’qil or Mughfal (the narrator is unsure) that he reports from the Prophet ﷺ that he ﷺ said: "When the time for prayer comes to you in a sheepfold, then pray in it, for it is mercy and blessing. And when the time for prayer comes to you in a camel enclosure, then leave it and pray (outside), for it is created from the jinn. Do you not see that when it is angry, how loudly it bellows from its nose?"
Hadith Referenceمسند الإمام الشافعي / كتاب الصلاة / 175
Hadith Takhrijاسنادة ضعيف: الا ان المتن صحيح اخرجه النسائي المساجد، باب ذکر نهى النبي عن الصلاة في اعطان الابل: 736 - وابن ماجه المساجد، باب الصلاة، في اعطان الابل ومداح الغنم: 768، 769.