It is cited in Ṣaḥīḥ Abī Dāwūd (1785). It has also been narrated from ʿUthmān, and its sources are documented in my commentary on al-Aḥādīth al-Mukhtārah (no. 356).
This hadith contains a noble prophetic directive for treating sexual arousal and the intensity of desire in young people who are unable to marry: namely, fasting. It is therefore not permissible for them to resort to the secret habit of masturbation. For they are like those to whom it was said: “Would you exchange that which is inferior for that which is better?”
Moreover, masturbation itself is not among the qualities of the believers whom Allah describes in the Noble Quran:
“And those who guard their chastity, except with their wives or those whom their right hands possess, for then they are free from blame. But whoever seeks beyond that, it is they who are the transgressors.”
ʿĀʾishah, may Allah be pleased with her, said in her exegesis: “Whoever seeks beyond what Allah has given him in marriage or made his possession has transgressed.” Al-Ḥākim narrated it (2/393) and declared it authentic according to the conditions of the two shaykhs; al-Dhahabī concurred with him.
1831 — “Allah created John, son of Zechariah, a believer in his mother’s womb, and created Pharaoh a disbeliever in his mother’s womb.”
It was narrated by Abū al-Shaykh in al-Tārīkh (p. 128), Ibn Ḥayawayh in his Ḥadīth (41/2), al-Lālikāʾī in al-Sunnah (130/1–2), and Abū Nuʿaym in Akhbār Aṣbahān (2/190), through Naṣr ibn Ṭarīf, from Qatādah, from Abū Ḥassān, from Nājiyah ibn Kaʿb, from ʿAbd Allāh, attributed to the Prophet.
I say: This chain is very weak. There is unanimous agreement on the weakness of this Naṣr ibn Ṭarīf; indeed, Yaḥyā said of him: “He was among those known for fabricating hadith.” However, he was not alone in narrating it. Al-Ṭabarānī (no. 10543) said: Aḥmad ibn Dāwūd, the Meccan, narrated to us; Shādhdh ibn al-Fayyāḍ informed us; Abū Hilāl informed us from Qatādah with the same report.