HETERIM FOR DIVREI TORAH IN UNCLEAN PLACES [Torah :Beis ha'Kisei: bathhouse]
Gemara
Kidushin 33a - Question: R. Shimon bar Rebbi once complained to Rebbi that R. Chiya, whom he taught, did not rise for R. Shimon in the bathhouse. Rebbi suggested 'perhaps he was thinking about what you taught him, and he did not notice you.'
Inference: Had he noticed, he would be obligated to rise!
Answer: One must rise in the outer rooms, but not in the inner rooms.
Support: Surely this was in the outer rooms, for Rabah bar bar Chanah taught that one not may think about Torah in a privy or (the inner rooms of) a bathhouse!
Rejection: Perhaps it was Ones (he could not avoid thinking about Torah).
Shabbos 40b - R. Yitzchak bar Avodimi: I once went to bathe in back of Rebbi. I wanted to warm up oil (in a flask) in the water and anoint him with it. He told me to put the oil in a Kli Sheni (but not it in the bath, which is like a Keli Rishon).
Question: How could Rebbi say this in the bath? (It is like Divrei Torah!)
Suggestion: Perhaps Divrei Torah are forbidden only in Lashon ha'Kodesh.
Rejection: Abaye taught that secular matters are permitted even in Lashon ha'Kodesh, but Divrei Torah are forbidden in any language!
Answer: One may stop someone from transgressing.
Support: A Talmid followed R. Meir into a bathhouse and wanted to wash the floor and apply scented water to it. R. Meir said that these are forbidden. This shows that the Isur does not apply to preventing transgression.
Avodah Zarah 44b - Mishnah: A Nochri Min saw R. Gamliel bathing in the bathhouse of Afroditi (an idolatry).
The Min: You are forbidden - "Lo Yidbak b'Yadcha Me'umah Min ha'Cherem"!
R. Gamliel replied 'we do not answer in a bathhouse.' Afterwards, he explained that here, Afroditi is not treated like a god, therefore it is permitted.
Question: How could R. Gamliel say in the bathhouse 'we do not answer...'?
Answer (Beraisa): He said this after he left.
Zevachim 102b (Rav): In the bathroom, R. Elazar b'Rebbi Shimon composed a dialogue to prove that a Tevul Yom does not receive a share of Kodshim.
Question: Rabah bar bar Chanah taught that one may think about Torah anywhere except for a bathhouse or privy!
Answer: Ones is different (R. Elazar could not avoid thinking about Torah).
Rishonim
Rif and Rosh (Shabbos 19a and 3:12): One may think about Torah anywhere except for a privy or bathhouse. Divrei Kedushah are forbidden in any language; secular matters may be said even in Lashon ha'Kodesh. One may prevent transgression even in Lashon ha'Kodesh, for Rebbi and R. Meir did so.
Ran (DH v'Ashma'inan): Rebbi said to put the oil in a Keli Sheni. This teaches that one may say something from which Halachos can be inferred, even if it is not needed to separate from Isur.
Gra (OC 85 DH uv'Inyanei): The Rashba explains that he could have merely said that he does not need this. Since he said how to do it, this shows that one may say it like a Hora'ah.
Ran (ibid.): The Yerushalmi permits asking laws of a privy or bathhouse while there. The Ramban says that the Bavli permits only to separate from Isur.
Rambam (Hilchos Kri'as Shma 3:5): One may prevent transgression in a bathhouse or privy, even in Lashon ha'Kodesh and regarding Kodesh matters.
Kesef Mishneh: Rebbi only said what to do. R. Meir ruled that we may not do this in a bathhouse. This is what the Rambam means by 'Kodesh matters'.
Maharshal: One might have thought that Rebbi requested a Kli Sheni because he did not want the oil to be so hot.
Tosfos (Avodah Zarah 44b DH Tana): R. Shmuel says that R. Gamliel did not answer at all in the bathhouse. The Ri says that in the middle room, where one may give 'Shalom' to avoid enmity, he said 'we do not answer in a bathhouse'. In the outer room, where Divrei Torah are permitted, he explained the law.
Poskim
Rema (62:4): If one is in a place that is not totally clean (at the time for Kri'as Shema) and he cannot clean it, he should think Shema in his heart.
Magen Avraham (2): The middle room of a bathhouse is such a place.
Taz (1): Likewise, if one woke up at night and wants to drink but cannot wash his hands, he should think the Berachah in his heart.
Rebuttal (Mishnah Berurah 7,8): One is not Yotzei through Hirhur. He should get up and wash. If this is impossible, he should clean his hands on the wall or anything else. This suffices even if he touched covered parts of the body.
Rema: If it is utterly filthy he may not think about Divrei Torah.
Mishnah Berurah (9): If one is obligated to say Shema or a Berachah but may not, he should think about his obligation and feel bad that he cannot fulfill it
Rema (OC 85:2): One may not learn even laws of bathhouses in a bathhouse.
Beis Yosef (DH v'Chosav ha'Rav): R. Mano'ach says that the Yerushalmi permits Hirhur in a privy. The Ra'avad says that the Bavli does not argue. The Bavli forbids Hirhur, i.e. to purposely think about Torah. If Torah is fluent in one's mouth and he thinks there b'Ones, it is permitted. Zevachim 102b proves this. R. Elazar was permitted, for it was Ones. Rashi explains that the teaching was fluent in his mouth, and he thought about it against his will.
Birkei Yosef (1 DH v'Zeh): Eliyahu Rabah, citing the Drishah, learns from Zevachim 102b that since Ones permits him to think about Torah, he may even say the words out loud. Surely this is forbidden! R. Elazar later taught in the Beis ha'Mikdash what he thought about in the Beis ha'Kisei.
Mishnah Berurah (6): 'It is permitted', i.e. he is not liable, since it was b'Ones, but surely he must try to avoid Hirhur. All the more so speech is forbidden!
Shulchan Aruch (85:2): One may prevent transgression in a bathhouse or privy, even in Lashon ha'Kodesh and regarding Kodesh matters.
Kaf ha'Chayim (16): If one starts thinking of a woman or any evil thought, he may divert his mind to Torah, for this is preventing transgression.
Rema: Where Hirhur is permitted, one may give a ruling, but without the reason.
Gra (DH uv'Makom): The Ran says that the Heter to answer in the middle room was not due to enmity. Rather, Hirhur is permitted there, and saying a ruling without the reason is like Hirhur.
Mishnah Berurah (14): Some permit saying it like a Hora'ah. Others forbid. If people are cutting hair on Erev Pesach after midday, one should say 'we do not cut hair', not 'it is forbidden'. If his words are not heeded, he may elaborate as much as needed.
Mishnah Berurah (15): This is when the place is not totally clean, or his hands, e.g. he touched a covered part of the body. If the place or his hands are filthy, even Hirhur is forbidden.