It is reported on the authority of Sa'b b. Jaththama that the Prophet of Allah (ﷺ), when asked about the women and children of the polytheists being killed during the night raid, said:
They are from them. (Sahih Muslim 1745 a)
What Non-Muslims MISERABLY failed to understand is that children and women were being used against Muslims in the times of war.
Young boys used to be enlisted in the times of war during ancient Arabian times.
The story of our beloved Prophet Muhammad (Sallallahu'alayhiwassalam) getting attacked during his visit to the city of Tai'f has been well recorded in the Sirah. People of Tai'f used children to attack him. It was the children who attacked him to the extent that they wounded him.
Here is wikipedia article:-
Furthermore, the Arabic word used in the hadith is ذَرَارِيِّهِمْ
This word does not necessarily mean "children" rather it could also mean "progeny" (i.e. it could refer to young boys also)
There is evidence in the Hadith scripture that only those boys were intentionally killed who reached the age of puberty
Ibn Majah narration says,
“I heard 'Atiyyah Al-Quradhi say: 'We were presented to the Messenger of Allah (ﷺ) on the Day of Quraidhah. Those whose pubic hair had grown were killed, and those whose pubic hair had not yet grown were let go. I was one of those whose pubic hair had not yet grown, so I was let go.”
(Ibn Majah, Vol. 3, Book 20, Hadith 2541)
This narration clearly proves two things:-
It is quite possible that Children who did not reached puberty also participated in the war, as the incident of tai'f proves.
Secondly, only those young boys were killed who REACHED PUBERTY as the narration clearly suggests that those boys who did not have pubic here were SPARED
This shows that Prophet (Sallallahu'alayhiwassalam) never allowed anyone to kill children intentionally.
Furthermore, when Prophet (Sallallahu'alayhiwassalam) was asked about possibility of women and their progeny getting harmed during night raid, his response was not "Yes" right away. In fact, his response was "They are from them", this shows that they were possibly hostile towards Muslims.
There is a general consensus among Muslims that this hadith was only for a particular group of women and their progeny who were possibily harmful towards Muslims.
Here are the following hadith that clearly proves that Prophet muhammad (Sallallahu'alayhiwassalam) CLEARLY FORBADE killing women and children:-
“We went out to fight alongside the Messenger of Allah (ﷺ), and we passed by a slain woman whom the people had gathered around. They parted (to let the Prophet (ﷺ) through) and he said: ‘This (woman) was not one of those who were fighting.’ Then he said to a man: ‘Go to Khalid bin Walid and tell him that the Messenger of Allah (ﷺ) commands you: “Do NOT kill any WOMAN or any (farm) laborer.’” (Ibn Majah, Vol. 4, Book 24, Hadith) 2842)
Do not kill children or workers. (Ibn Majah, 2842)
During some of the Ghazawat of Allah's Messenger (Sallallahu'alayhiwassalam) a woman was found killed, so Allah's Messenger (Sallallahu'alayhiwassalam) FORBADE the killing of women and children. (Sahih Al-Bukhari 3015)
Allah's Messenger (Sallallahu'alayhiwassalam) disapproved the killing of women and children (Sahih Al-Bukhari 3014)
After analyzing all the hadith in proper context it becomes pretty obvious that permissibility of killing those women and young boys was specific in nature, as those polytheist were hostile to Muslims.
HADITH LITERATURE PROVES that even NON-MUSLIM KILLED LITTLE BOYS OF THE MUSLIM ARMY
Here is the Hadith that proves that even Non-Muslims killed young boys like Haritha of the Muslim army:-
Haritha was martyred on the day (of the battle) of Badr, and he was a YOUNG BOY THEN. (Sahih al-Bukhari 3982)
The Hadith literature proves that Prophet (Sallallahu'alayhiwassalam) had divine knowledge about progeny of people.
It was narrated that Abu Sa'eed Al-Khudri said:
"When he was in Yemen, Ali sent a piece of gold that was still mixed with sediment to the Messenger of Allah, and the Messenger of Allah distributed it among four people: Al-Aqra' bin Habis Al-Hanzali, 'Uyaynah bin Badr Al-Fazari, 'Alqamah bin 'Ulathah Al- 'Amiri, who was from Banu Kilab and Zaid Al-Ta'I who was from Banu Nabhan. The Quraish" - he said one time: became angry and said: 'You give to the chiefs of Najdand that, so as to soften their hearts toward Islam.' Then a man with a thick beard, prominent cheeks, and a shaven head came and said: 'Fear Allah. O Muhammad! He said: 'Who would obey Allah if I disobeyed Him? (Is it fair that) He has entrusted me with all the people of the Earth but you do not trust me?' Then the man went away, and a man from among the people, whom they (the narrators) think was Khalid bin Al-Walid, asked for permission to kill him. The Messenger of Allah said: 'Among the OFFSPRING of this man will be some people who will recite the Qur'an but it will not go any further than their throats. THEY WILL KILL THE MUSLIMS but leave the idol worshippers alone, and they will passes through Islam as an arrow passes through the body of the target. If I live to see them. I will kill them all, as the people of 'Ad were killed."'(Sunan an-Nasa'i 2578)
So we can see that even Non-Muslims were killing little and young boys, so God chose to wipe them out because of their rebellion, as they were like their parents.The Hadith also proves that Prophets had divine knowledge about offspring of people just like Khidr (Alayhisalam) had knowledge about rebellious son of a man and a woman.