It was narrated by Abu Dawud (3). This is a specific [ruling] which takes precedence over the general [nature] of what they narrated. From Jabir ibn Samura, that a man asked the Messenger of Allah (may Allah bless him and grant him peace): "Shall we pray in sheep pens?" He said: "Yes." He asked: "Shall we pray in camel resting places?" He said: "No." Narrated by Muslim (4). From al-Bara', he said: The Messenger of Allah (may Allah bless him and grant him peace) said: "Do not pray in camel resting places, for they are from the devils." Narrated by Abu Dawud (5). From Usayd ibn Hudayr, that the Messenger of Allah (may Allah bless him and grant him peace) said: "Pray in sheep pens, and do not pray in camel resting places." Narrated by Imam Ahmad in his "Musnad" (6). A prohibition implies prohibition [tahrim], and this is a specific [ruling] that takes precedence over the general [nature] of what they narrated. This hadith was also narrated from Ibn 'Umar, Abu Hurayra, and 'Abd Allah ibn Mughaffal; al-Athram narrated them (7).
As for the latrine, the ruling is established regarding it by analogy [al-tanbih], because if one is prevented from praying in these places due to them being sites of impurity, then the latrine is prepared for and intended for impurity, so it is more appropriate that it be prohibited. Some of our companions said: If the one praying is aware of the prohibition in these places, his prayer is not valid, because he is disobedient by praying in them, and an act of disobedience cannot be an act of drawing near [qurba] nor an act of obedience. If he was not aware, is his prayer valid? There are two reports. The first is that it is not valid, because he prayed in a place where prayer is not valid with knowledge, so it is not valid with ignorance, like praying in an impure location.
(3) In: "Chapter: On places where prayer is not permitted," from Kitab al-Salah. Sunan Abi Dawud 1/114. It was also narrated by al-Tirmidhi, in: "Chapter: What has been narrated that the entire earth is a place of prostration except the graveyard and the bathhouse," from Abwab al-Salah. 'Aridat al-Ahwadhi 2/113, 114. And Ibn Majah, in: "Chapter: Places in which prayer is disliked," from Kitab al-Masajid. Sunan Ibn Majah 1/246. And al-Darimi, in: "Chapter: The entire earth is a means of purification except the graveyard and the bathhouse," from Kitab al-Salah. Sunan al-Darimi 1/323. And Imam Ahmad, in: al-Musnad 3/83, 96. (4) In: "Chapter: Ablution after eating camel meat," from Kitab al-Hayd. Sahih Muslim 1/275. It was also narrated by Imam Ahmad, in: al-Musnad 5/93, 98, 100, 106, 108. (5) In: "Chapter: Ablution after eating camel meat," from Kitab al-Tahara, and in: "Chapter: The prohibition of praying in camel resting places," from Kitab al-Salah. Sunan Abi Dawud 1/41, 115. (6) Al-Musnad 4/352. (7) They were also narrated by Imam Ahmad, from Abu Hurayra in al-Musnad 2/509, 4/150, and 'Abd Allah ibn Mughaffal al-Muzani in al-Musnad 4/86, 5/55, 57. And 'Uqba ibn 'Amir al-Juhani, al-Musnad 4/150. The hadith of Ibn 'Umar will follow.