He said to the Messenger of Allah ﷺ that he sometimes became sexually impure during the night. The Messenger of Allah ﷺ told him, "Perform ablution, wash your private part, then sleep."
أنه قال لرسول الله ﷺ: إنه يصيبه جنابة من الليل، فقال له رسول الله ﷺ: توضأ واغسل ذكرك، ثم نم.
Malik narrated it in Tahara (76) from Abdullah bin Dinar, from Abdullah bin Umar, from Umar bin Khattab, and he related the hadith. Bukhari transmitted it through Malik's route in Ghusl (290), as did Muslim in Hayd (306).In a version found in both of them, through a route other than Malik's, "Should any of us sleep while in a state of janabah?" He said, "Yes, if he performs wudu."