Anas reported that whenever the Messenger of Allah ﷺ entered the lavatory, he would say, "O Allah, I seek refuge in You from male and female devils."
حدثنا هشيم عن عبد العزيز
أن رسول الله ﷺ كان إذا دخل الخلاء قال يقول اللهم إني أعوذ بك من الخبث والخبائث
Its isnad is sahih. Abdul-Aziz is Ibn Suhayb, mentioned previously. The hadith was narrated by Bukhari 1/48, in the chapter on Purification, What one says upon entering the toilet, and by Muslim 1/283, no. 375, in the chapter on Menstruation, in similar wording, and by Abu Dawud 1/2, no. 4, in the same wording as Bukhari, and by Tirmidhi 1/11, no. 6, who said, hasan sahih, and by Ibn Majah 1/108, no. 296.