Those privies are attended by the devils, so if anyone of you goes to a privy, let him say: I seek refuge with Allah from the male and female devils
Authentic hadithعن زيد بن أرقم رضي الله عنه ، عن رسول الله صلى الله عليه وسلم قال:«إنَّ هذه الحُشُوشَ مُحْتَضَرَةٌ، فإذا أتى أحدُكم الخَلَاءَ فَلْيَقُلْ: أعوذُ باللهِ مِنَ الخُبُثِ والخَبَائث».
Zayd ibn Arqam (may Allah be pleased with him) reported that the Messenger of Allah (may Allah's peace and blessings be upon him) said: "Those privies are attended by the devils, so if anyone of you goes to a privy, let him say: I seek refuge with Allah from the male and female devils."
Explanation
The place where one relieves himself (privy) is attended by the Jinn and the devils who wait there to inflict harm and trouble on humans. A privy is a place where one's private parts are uncovered, and the name of Allah is not mentioned. So, when a Muslim goes there, he should say this supplication: I seek refuge with Allah from the males and females from among the devils.
Source · Narrated by Ibn Majah - Narrated by Abu Daoud - Narrated by Ahmad
From the Hadith Encyclopedia (hadeethenc.com).