—namely, that he did so as a way of legislating for the people—yet how could that be, when such an act is ordinarily hidden from view, as is perfectly clear?!
The correct position, therefore, is to declare the practice forbidden absolutely, whether in the open countryside or within built-up areas. This is the conclusion reached by al-Shawkani in both Nayl al-Awtar and al-Sayl al-Jarrar 1/69, where he writes:
“The real import of the prohibition is prohibition, and nothing alters that—not even the report that the Prophet ﷺ once did it—for we have already shown that a prophetic action does not override a statement directed specifically to the Ummah unless there is evidence that he meant them to imitate him in that matter; otherwise, the action is peculiar to him. This issue has been thoroughly examined and clarified in legal theory, and that is the truth, as any fair-minded person will see. Even if we were to assume that evidence existed establishing imitation in such a deed, its scope would be limited to inhabited buildings, for he was seen doing it in Hafsah’s apartment between two bricks.”
I add: His point is that the cited evidence does not in fact exist; hence the ruling remains general while the action pertains exclusively to him ﷺ.
As for Ibn ʿUmar’s remark in the narration of Marwan al-Asfar, quoted by the author after the preceding ḥadith—“He only forbade this in open space …” —it is not explicitly traced back to the Prophet. It could simply be Ibn ʿUmar’s own inference from the Prophet’s act in Hafsah’s house, and thus it cannot serve to restrict the prohibition to the desert, as al-Shawkani has explained. Whoever wishes may consult him, 1/73.
Supporting the general rule are the ḥadiths that forbid spitting toward the qiblah, whether inside or outside the mosque. Among them is his ﷺ saying, “Whoever spits toward the qiblah will come on the Day of Resurrection with his spittle between his eyes.” It is recorded in al-Ṣaḥīḥah, nos. 222 and 223. Al-Nawawī ruled categorically that it is prohibited under all circumstances—during prayer or outside it, in the mosque or elsewhere—and the same view was held by al-Ṣanʿānī, as I have cited there. If spitting toward the qiblah from within a building is forbidden and unlawful, then urinating or defecating in that direction is even more decisively prohibited. So take heed, O people of insight!