Sayyid Sabaq said in Fiqh-us-Sunnah:
كان رسول الله صلى الله عليه وسلم يجعل الرجال قدام الغلمان، والغلمان خلفهم، والنساء خلف الغلمان
The Messenger of Allah placed the men before the children and the children behind them and the women behind the children
[Reported by Ahmad and Abu Dawood]
Shaikh Al-Albani said commenting on this:
I say: The chain of these two narrations are weak. In them is Shahr and he is weak as has preceded more than once.
There has come authentic Ahaadith that the women pray in one row by themselves behind the men. As for placing the children behind them, then I did not find a Hadith besides the Hadith that the Messenger sallahu alayhi wa salam placed the men before the children and the children behind them, and the women behind the children. It can not be established as evidence [Note: Shaikh Al-Albani also graded this Hadith Daif in Daif Sunan Abi Dawood no. 677]. So there is no harm in the children standing with the men if the row is spacious. The orphan praying with Anas [in one row] behind the Prophet sallahu alayhi wa salam is proof for that [Reported by Al-Bukhari no. 874 and others].
[Taken from Tamam al-Minnah Ta’leeq ‘ala Fiqh-us-Sunnah written by Shaikh Al-Albani pg. 284]
Shaikh Bin Baz rahimahullah was asked:
Question: Some children arrive early on Jummah and people older than them come and take their place and put them in their place. They use as evidence the statement of the Prophet sallahu alayhi wa salam:
ليلني منكم أولو الأحلام والنهى
Let those be nearest to me who are mature and endowed with understanding (of the religion), [Saheeh Muslim]. So is this correct?
Answer: “this is the opinion of some people of knowledge who see that the children stand behind the men, however, this opinion is disputable.
What is more correct is that if they come forward, it is not allowed to put them back. If they come first to the first row or to the second row, those who come after them cannot precede them because they preceded to a right that other than them did not precede to. It is not allowed to put them behind due to the general ahaadith about that. Putting them back is running them away from prayer and competing towards it. It is not befitting for that.
However, if the people gather such that they come together in a travel or because of a cause, then they put the men first, then the children second, then the women after them if that happens and they gather together. As for taken them out from the rows and putting them in the place of the older people who come after them, then that is not allowed as we mentioned. As for the statement of the Prophet sallahu alayhi wa salam:
ليلني منكم أولو الأحلام والنهى
Let those be nearest to me who are mature and endowed with understanding (of the religion), [Saheeh Muslim]
So its intent is the incitement to competing to prayer from the people of understanding and maturity and that they be in front of the people. It does not mean putting behind those who arrive before them because it opposes the legislated evidences of which we mentioned”.
[Taken from here]
Imam Ibn Abdul Barr rahimahullah said:
“And this Hadith also proves that if a child understands the prayer, then prays with the congregation and he enters with them in the row, if he is safe from playing and harm and he is from those who understand the meaning of the prayer…”
[Taken from al-Istithkaar al-Jaami li-Mathaahib Fuqahaa al-Amsaar wal-Ulama al-aqtaar]
And Allah knows Best.
Faisal Ibn Abdul Qaadir Ibn Hassan