Umar mentioned to the Messenger of Allah ﷺ that he sometimes became sexually impure during the night. The Messenger of Allah ﷺ said, "Perform ablution, wash your private part, then go to sleep."
أخبرنا قتيبة عن مالك عن عبد الله بن دينار
ذكر عمر لرسول الله ﷺ أنه تصيبه الجنابة من الليل فقال رسول الله ﷺ توضأ واغسل ذكرك ثم نم
Bukhari transmitted it, ghusl, chapter on a person in a state of janabah performing wudu then sleeping, hadith no. 290, and Muslim, menstruation, chapter on the permissibility of a person in a state of janabah sleeping, etc., hadith no. 306, from the hadith of Malik, with this wording. It is also in Muwatta (Yahya narration), 1/47, and Kubra, hadith no. 256.