The Sages taught: Because of three things one does not enter a ruin: because of suspicion, because of collapse, and because of mazikin [harmful spirits].It should not trouble us that the brayta lists three reasons. So long as they are all true reasons, why not? The setama degamara, however, assumes that if three are given, each must have a chance to hold absent the other two. And so what follows is an extremely systematic analysis, as to how one can construct a situation for each of the three in the absence of the other two.
It would be sufficient to say, because of falling debris'? When the ruin is new.1 But it would be sufficient to say: 'because of demons'? — When there are two people.2 If there are two people, then there is no suspicion either? — When both are licentious [there is suspicion]. — [It states] 'Because of falling debris'. It would be sufficient to say: 'because of suspicion and demons'? — When there are two decent people. [It states] 'Because of demons'. It would be sufficient to say; 'because of suspicion and falling debris'? — When there are two decent people going into a new ruin. But if there are two, then there is no danger of demons either? — In their haunt there is danger. If you like I can say, indeed the reference is to one man and to a new ruin which was situated in the fields; in which case there is no suspicion, for a woman would not be found in the fields, but the danger of demons does exist.This is unnecessary, and indeed seems to me somewhat farfetched. In particular, where both are licentious?! Prutzim rather than kesheirim? Does the gemara really need to address them, to give them this cause? Surely prutzim would simply enter the ruin and disregard the brayta. (One can answer that one of them is a parutz, and so the one cannot rely on the other for chashad purposes; or, like one rishon, define kasher as a special level of tzadik, and parutz as a regular person; though both have drawbacks).
I have, though, sometimes noticed a trend in which not only is a non-rationalist reason given for a practice, but a rationalist reason alongside it. For example, consider the reason for Mezuzah, from parshas vaEschanan which just passed.
In the gemara in Menachot 33, there are two positions,one (Rabanan) which stresses the psychological impact of encountering it as one enters one's home, while the other (R' Chanina of Sura) regards it as a protective measure of the entire home.So too, we have an extreme derech hateva reason: danger of collapse; a quasi-mystical reason: demons; and a moral/ethical/social/halachic reason: suspicion of sexual impropriety.
The Rambam, and other rationalists, do not believe in the existence of sheidim. And in general, he leaves out sheidim and other similar matters out of Mishneh Torah. As such, it is a good exercise to see just what he has to say about davening in a ruin.
The Rambam mentions this halacha in two places. Once, in hilchos tefillah, 5:6:
ז [ו] תִּקּוּן הַמָּקוֹם כֵּיצַד: יַעֲמֹד בְּמָקוֹם נָמוּךְ, וְיַחְזִיר פָּנָיו לַכּוֹתָל. וְצָרִיךְ לִפְתֹּחַ חַלּוֹנוֹת אוֹ פְּתָחִים, כְּנֶגֶד יְרוּשָׁלַיִם, כְּדֵי לְהִתְפַּלַּל כְּנֶגְדָּן, שֶׁנֶּאֱמָר "וְכַוִּין פְּתִיחִין לֵהּ בְּעִלִּיתֵהּ, נֶגֶד יְרוּשְׁלֶם" (ראה דנייאל ו,יא). וְקוֹבֵעַ מָקוֹם לִתְפִלָּתוֹ, תָּמִיד. וְאֵין מִתְפַּלְּלִין, בְּחֻרְבָה; וְלֹא לַאֲחוֹרֵי בֵּית הַכְּנֶסֶת, אֵלָא אִם כֵּן הִחְזִיר פָּנָיו לְבֵית הַכְּנֶסֶת. וְאָסוּר לֵישֵׁב בְּצַד הָעוֹמֵד בַּתְּפִלָּה, אוֹ לַעֲבֹר לְפָנָיו--עַד שֶׁיַּרְחִיק מִמֶּנּוּ אַרְבַּע אַמּוֹת.
but he does not give reasons. So too in hilchos rotzeach vishmirat nefesh, perek 12, about entering a ruin in general:
ה [ו] וְכֵן לֹא יִנְעֹץ הַסַּכִּין בְּתוֹךְ הָאֶתְרוֹג אוֹ בְּתוֹךְ הַצְּנוֹן--שֶׁמֶּא יִפֹּל אָדָם עַל חֻדָּהּ, וְיָמוּת. וְכֵן אָסוּר לָאָדָם לַעֲבֹר תַּחַת קִיר נָטוּי, אוֹ עַל גֶּשֶׁר רָעוּעַ, אוֹ לְהִכָּנֵס לְחֻרְבָה; וְכֵן כָּל כַּיּוֹצֶא בְּאֵלּוּ מִשְּׁאָר הַסַּכָּנוֹת, אָסוּר לַעֲמֹד בִּמְקוֹמָן.
We can also check out what the Meiri has to say about it:
"It is of the traits and approach of the Chachamim that one should not enter a ruin, nor any other place that would provide an opening, for those who see, for suspicion due to his entering those places. And even if he needs to enter there in order to pray in seclusion, it is better for him to play on the road. And when he prays, he should pray a short tefillah is he fears that passersby may interrupt him, rather then entering into the ruin. 'A short tefillah' -- this is not absolutely short, for behold they only permitted this because of wild animals and robbers. Rather, havineinu; or the beginning and end of each bracha [of Shmoneh Esrei], as is explained in perek Tefillat HaShachar [29b].
Even in a place where there is no worry [of suspicion] such as if there are two who are decent people known for their fear of sin, he needs to take care not to enter the ruin because of fear of falling debris, and so too from fear of anything which would be a concern for danger due to his entering there."
That last (bolded) phrase certainly seems to me to be a dance around the word mazikin as demons; yet he clearly does take to heart, and to halacha, the gemara and brayta's concern."
Though I am not at all convinced that this was the intent of the brayta and gemara, one can generalize from mazikin, or even take mazikin not as demons/evil spirits, but as harmful entities of any sort. Consider the Biblical discussions of seirim, taken as demons. E.g. Yeshaya 13:
We see all sorts of animals in abandoned buildings. And even if we feel compelled to take reference to seirim to mean that they must exist, seirim does not need to mean demons. Malbim indeed takes it as sheidim, writing:
הם השדים, כמו לשעירים אשר הם זונים אחריהם, ונקראו כן, לפי שהם נראים כדמות שעירים למאמין בהם.
וכן תרגם יונתן:
ושידין יחייכון תמן.
Ibn Ezra, who does not believe in sheidim, seems to say (if I understand him correctly) that they are animals similar in form to sheidim. Thus, he writes on the pasuk that they are: כדמות שדים והם שעירים ברים.
A note of caution. Disbelief in sheidim may be hazardous to your health. Consider what happened to Ibn Ezra, according to the testimony of Rabbi Moshe Taku:
"Ibn Ezra wrote in his book," he says, "'Of a surety there are no demons in the world!' .Verily he erred in this matter, for they were ever at his side . . . and indeed they proved their existence to at him. I have heard from the people of Iglant [England?], where he died, that once when he was travelling through a forest he came upon a large band of black dogs who glared at him balefully; undoubtedly these were demons. When he had finally passed through their midst he fell seriously ill, and eventually he died of that illness."