Whenever the Messenger of Allah ﷺ entered the toilet, he would say, "I seek refuge in Allah from male and female evil spirits."
حدثنا عمرو بن رافع حدثنا إسمعيل ابن علية عن عبد العزيز بن صهيب
كان رسول الله ﷺ إذا دخل الخلاء قال أعوذ بالله من الخبث والخبائث
Muslim narrated it in the chapter on menstruation, in the section on what one says when intending to enter the toilet, hadith no. 375, through the hadith of Ismail and others.