The Messenger of Allah ﷺ said, "These privies are frequented by devils, so when one of you enters the lavatory, let him say, 'I seek refuge in Allah from male and female devils.'"
عن رسول الله ﷺ قال: إن هذه الحشوش محتضرة، فإذا أتى أحدكم الخلاء فليقل: أعوذ بالله من الخبث والخبائث.
Abu Dawud (6), Ibn Khuzayma (69), and Ibn Hibban (1408) all narrated it through routes from Shubah, from Qatada, from Nadr bin Anas, from Zayd bin Arqam, who related it.His saying, "frequented," means that the jinn frequent it, as Ibn Athir stated in Nihaya (1/399).