Shulchan Aruch 83:1 rules that one should not daven or learn Torah near an area designated for bathroom use. If however the bathroom contains walls then it is permitted. It writes there:
אסו' לקרות כנגד בית הכסא ישן אפי' פינו ממנו הצואה ויראה לי דהיינו כשאין לו מחיצות אבל אם יש לו מחיצות אף ע"פ שיש בו צואה קורא כנגדו בסמוך ואינו חושש אם אין מגיע לו ריח רע:
It is forbidden to recite [the Recitation of the Sh'ma] facing an old latrine, even if excrement has been emptied from it. And it seems to me that this is when there are no partitions, but if there are partitions, even though there is excrement, one recites facing it, adjacent to it, and one need not be concerned as long as no bad smell reaches one. (Sefaria translation)
However this point about a walled-off bathroom is disputed by the Taz 83:1 and says that one shouldn't daven or learn even with a walled-off area.
I am reminded about the famous story of the brothers Reb Elimelech of Lizhensk and Reb Zusha Anipoli who were wrongly sent to prison. When the time came for mincha, they noticed that they couldn't daven due to a chamber pot being in the cell with them. Reb Elimelech was noticeably upset, but Reb Zusha reminded him that this must be the will of G-d and therefore they were players in the part of Hashem's masterplan. This made them rejoice and soon they started dancing causing quite a commotion. When a guard asked a nearby prisoner what they were so happy about he motioned to the chamber pot in the cell. The guard swiftly took action and happily removed the pail. The brothers were then free to daven mincha. The story is well-known and is also related here as well as many other places.