Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
muslim:1812bAbū Bakr b. Abū Shaybah And ʾIsḥāq b. Ibrāhīm > Ḥātim b. Ismāʿīl > Jaʿfar b. Muḥammad from his father > Yazīd b. Hurmuz > Najdah Katab > Ibn ʿAbbās Yasʾaluh > Khilāl Bimithl Ḥadīth Sulaymān b. Bilāl Ghayr

The Messenger of Allah ﷺ used not to kill the children, so thou shouldst not kill them unless you could know what Khadir had known about the child he killed, or you could distinguish between a child who would grow up to he a believer (and a child who would grow up to be a non-believer), so that you killed the (prospective) non-believer and left the (prospective) believer aside.  

مسلم:١٨١٢bحَدَّثَنَا أَبُو بَكْرِ بْنُ أَبِي شَيْبَةَ وَإِسْحَاقُ بْنُ إِبْرَاهِيمَ كِلاَهُمَا عَنْ حَاتِمِ بْنِ إِسْمَاعِيلَ عَنْ جَعْفَرِ بْنِ مُحَمَّدٍ عَنْ أَبِيهِ عَنْ يَزِيدَ بْنِ هُرْمُزَ أَنَّ نَجْدَةَ كَتَبَ إِلَى ابْنِ عَبَّاسٍ يَسْأَلُهُ عَنْ خِلاَلٍ بِمِثْلِ حَدِيثِ سُلَيْمَانَ بْنِ بِلاَلٍ غَيْرَ

أَنَّ فِي حَدِيثِ حَاتِمٍ وَإِنَّ رَسُولَ اللَّهِ ﷺ لَمْ يَكُنْ يَقْتُلُ الصِّبْيَانَ فَلاَ تَقْتُلِ الصِّبْيَانَ إِلاَّ أَنْ تَكُونَ تَعْلَمُ مَا عَلِمَ الْخَضِرُ مِنَ الصَّبِيِّ الَّذِي قَتَلَ وَزَادَ إِسْحَاقُ فِي حَدِيثِهِ عَنْ حَاتِمٍ وَتُمَيِّزَ الْمُؤْمِنَ فَتَقْتُلَ الْكَافِرَ وَتَدَعَ الْمُؤْمِنَ