Children in the military
Military academics in the US have characterized military training as "intense indoctrination" in conditions of sustained stress, the primary purpose of which is to establish the unconditional and immediate obedience of recruits. The research literature has found that adolescents are more vulnerable than adults to a high-stress environment, particularly those from a background of childhood adversity. It finds in particular that the prolonged stressors of military training are likely to aggravate pre-existing mental health problems and hamper healthy neurological development.
Military settings are characterized by elevated rates of bullying, particularly by instructors. In the UK between 2014 and 2020, for example, the army recorded 62 formal complaints of violence committed by staff against recruits at the military training centre for 16- and 17-year-old trainee soldiers, the Army Foundation College. Joe Turton, who joined up aged 17 in 2014, recalls bullying by staff throughout his training. For example:

The corporals come into the hangar where we sleep and they're wild-eyed, screaming, shoving people out. A massive sergeant lifts a recruit in the air and literally throws him into the wall. A corporal smacks me full-force around the head—I've got my helmet on but he hits me so hard that I'm knocked right over, I mean this man's about 40 and I'm maybe 17 by then. A bit later, we're crawling through mud and a corporal grabs me and drags me along the ground, half-way across a field. When he lets go I'm in that much pain that I'm whimpering on the ground. When the other corporal, the one who hit me, sees me crying on the ground, he just points at me and laughs.Elevated rates of sexual harassment are characteristic of military settings, including the training environment. Between 2015 and 2020, for example, girls aged 16 or 17 in the British armed forces were twice as likely as their same-age civilian peers to report rape or other sexual assault.

International law: 

Recruitment and use of children: 

Definition of child: The Convention on the Rights of the Child defines a child as any person under the age of 18. The Paris Principles define a child associated with an armed force or group as:

...any person below 18 years of age who is or who has been recruited or used by an armed force or armed group in any capacity, including but not limited to children, boys and girls, used as fighters, cooks, porters, messengers, spies or for sexual purposes. The document is approved by the United Nations General Assembly. It does not only refer to a child who is taking or has taken a direct part in hostilities.

Children aged under 15: The Additional Protocols to the 1949 Geneva Conventions (1977, Art. 77.2), the Convention on the Rights of the Child (1989), and the Rome Statute of the International Criminal Court (2002) all forbid state armed forces and non-state armed groups from using children under the age of 15 directly in armed conflict (technically "hostilities"). This is now recognised as a war crime.

Children aged under 18: Most states with armed forces are also bound by the higher standards of the widely ratified Optional Protocol on the Involvement of Children in Armed Conflict (OPAC) (2000) and the Worst Forms of Child Labour Convention (1999), which forbid the compulsory recruitment of those under the age of 18. OPAC also requires governments that still recruit children (from age 16) to "take all feasible measures to ensure that persons below the age of 18 do not take a direct part in hostilities". In addition, OPAC forbids non-state armed groups from recruiting children under any circumstances, although the legal force of this is uncertain.
The highest standard in the world is set by the African Charter on the Rights and Welfare of the Child, which forbids state armed forces from recruiting children under the age of 18 under any circumstances. Most African states have ratified the Charter.

Limitations and loopholes: None of the above treaties either explicitly forbids the indirect participation of children in "hostilities", or from contributing to a military operation in a stand-off position (i.e. away from hostilities).

Standards for the release and reintegration of children: OPAC requires governments to demobilise children within their jurisdiction who have been recruited or used in hostilities and to provide assistance for their physical and psychological recovery and social reintegration. Under war, civil unrest, armed conflict and other emergency situations, children and youths are also offered protection under the United Nations Declaration on the Protection of Women and Children in Emergency and Armed Conflict. To accommodate the proper disarmament, demobilisation and reintegration of former members of armed groups, the United Nations started the Integrated DDR Standards in 2006.

War crimes: Opinion is currently divided over whether children should be prosecuted for war crimes. International law does not prohibit the prosecution of children who commit war crimes, but Article 37 of the Convention on the Rights of the Child limits the punishment that a child can receive: "Neither capital punishment nor life imprisonment without possibility of release shall be imposed for offenses committed by persons below eighteen years of age."

Example: Sierra Leone: In the wake of the Sierra Leonean Civil War, the UN mandated the Special Court for Sierra Leone (SCSL) to try former combatants aged 15 and older for breaches of humanitarian law, including war crimes. However, the Paris Principles state that children who participate in armed conflict should be regarded first as victims, even if they may also be perpetrators:

... [those] who are accused of crimes under international law allegedly committed while they were associated with armed forces or armed groups should be considered primarily as victims of offenses against international law; not only as perpetrators. They must be treated by international law in a framework of restorative justice and social rehabilitation, consistent with international law which offers children special protection through numerous agreements and principles.
This principle was reflected in the Court's statute, which did not rule out prosecution but emphasised the need to rehabilitate and reintegrate former child soldiers. David Crane, the first Chief Prosecutor of the Sierra Leone tribunal, interpreted the statute in favour of prosecuting those who had recruited children, rather than the children themselves, no matter how heinous the crimes they had committed.

Example: Omar Khadr: In the US, prosecutors charged Omar Khadr, a Canadian, for offences they alleged he committed in Afghanistan while under the age of 16 and fighting for the Taliban against US forces. These crimes carry a maximum penalty of life imprisonment under US law. In 2010, while under torture and duress, Khadr pleaded guilty to murder in violation of the laws of war, attempted murder in violation of the laws of war, conspiracy, two counts of providing material support for terrorism, and spying. The plea was offered as part of a plea bargain, which would see Khadr deported to Canada after one year of imprisonment to serve seven further years there. Omar Khadr remained in Guantanamo Bay and the Canadian government faced international criticism for delaying his repatriation. Khadr was eventually transferred to the Canadian prison system in September 2012 and was freed on bail by a judge in Alberta in May 2015. As of 2016, Khadr was appealing his US conviction as a war criminal.
Before sentencing the Special Representative to the UN Secretary-General for Children and Armed Conflict wrote to the US military commission at Guantanamo appealing unsuccessfully for Khadr's release into a rehabilitation program. In her letter she said that Khadr represented the "classic child soldier narrative: recruited by unscrupulous groups to undertake actions at the bidding of adults to fight battles they barely understand".

The role of the United Nations: 

Background: Children's rights advocates were left frustrated after the final text of the convention on the Rights of the Child (1989) did not prohibit the military recruitment of all children under the age of 18, and they began to call for a new treaty to achieve this goal. As a consequence the newly formed Committee on the Rights of the Child made two recommendations: first, to request a major UN study into the impact of armed conflict on children; and second, to establish a working group of the UN Commission on Human Rights to negotiate a supplementary protocol to the convention. Both proposals were accepted.
Responding to the committee on the Rights of the Child, the UN General Assembly acknowledged "the grievous deterioration in the situation of children in many parts of the world as a result of armed conflicts" and commissioned the human rights expert Graça Machel to conduct a major fact-finding study. Her report, Impact of Armed Conflict on Children (1996), was particularly concerned with the military use of younger children, which was killing, maiming, and psychiatrically injuring many thousands every year. It noted:

Clearly one of the most urgent priorities is to remove everyone under 18 years of age from armed forces.
Meanwhile, the UN Commission on Human Rights established a working group to negotiate a treaty to raise the legal standard. After a global campaign and complex negotiations, the new treaty was agreed in 2000 as the Optional Protocol to the convention on the Rights of the Child on the Involvement of Children in Armed Conflict. The treaty prohibited the direct participation of all children in armed conflict for the first time, while continuing to allow state armed forces (though not non-state armed groups) to recruit children from age 16. The protocol came into force on 12 February 2002.

Special Representative of the Secretary-General for Children and Armed Conflict: The Machel Report led to a new mandate for a Special Representative of the Secretary-General for Children and Armed Conflict (SRSG-CAAC).