Islamic Ruling on Talking While Sitting in the Toilet
According to Islamic scholars, talking while relieving oneself in the toilet is disliked, but it is allowed in cases of need.

According to a hadith narrated by Abu Saeed Khudri, the Prophet Muhammad ﷺ said that two people should not relieve themselves while exposing their private parts and talking to each other, because Allah becomes angry with this act.
Based on this hadith, Islamic scholars have stated that relieving oneself in an open place without any cover and talking during that time is disliked and prohibited. For this reason, talking in the toilet is considered makrooh according to Islamic ruling and fatwa. A person should avoid it as much as possible.
However, Islamic scholars also mentioned that if there is a strong need or necessity, then speaking is allowed. Imam Khateeb Sharbini رحمه الله clearly stated that speaking during relieving oneself, whether with remembrance or other speech, is disliked except in cases of necessity.