Child soldiers are a trope of SF that occurs relatively really, and is handled seriously even less often. More common are situations like that of the Hunger Games, or Lord of the Flies, in which children are shown combating one another, but are not actually soldiers. There are some works that show children conscripted into armed forces, but most often it is only the protagonists, and for reason of their special abilities or a necessity imposed by the situation. For example, the children in the Ender's Game universe are recruited young in order that they can be trained more fully to command in space than a adult or teen could be. Battle School was not intended as a recruit camp, it was a device for finding the best possible commanders. That Ender, Bean, Petra, and the others were so young at the time was a product of chance. The IDF would doubtless preferred them to have been older at the time of the battle. This being the case Ender's Game is not focused on the idea of child soldiers; they are not intended ever to actually engage in direct combat.
A few works are more focused on the theme; The War against the Chtorr, Century Rain, and others. The most common reason behind the use of child soldiers seems either to be the flexibility of a young mind, or because numbers are crucial in a battle for survival.
In the Medieval period - and earlier/in other places - boys were made pages at about seven, becoming squires at around 12, and fighting in battle by mid-teens. This was a function not only of the training needed to be effective in medieval combat, but also of the reduced life expectancy; you grew up fast or died, even in other lifestyles.
In ancient Sparta training began at seven, again a result of the political situation in Sparta, where the helots outnumber them at all times.
More recently children have been used in various small wars and conflicts, most often in Africa; a quick google search shows that a horrific number are still forcefully recruited, brainwashed, and used against all and any opponents. Many of the terrorist organisations extant today continue with this tactic. On the other hand, many modern militaries allow recruits to join as young as 16, but do everything possible to keep them off the front lines until they are older, or place them in non-combat roles. And of course, in rebellions and uprising there are always teens and young children to be found, most notably in Europe during WW2, but also in other times and places. Even in armies which do not employ children or teens as soldiers they may serve as support personnel, cooking and maintaining equipment, although this seems to be uncommon.
As depraved as the action itself might be, there are several highly logical reasons that child soldiers are used. The impressionability of a child's mind enables them to be easily brainwashed - perhaps with the aid of drugs - making them suitable for terrorist acts, either covertly or in smash 'n burn raids. The fact that it is a innocent and harmless child attacking them makes the physiological trauma of those attack much deeper, especially in the case of soldiers forced to gun them down. And how do you decide to shoot the child running towed you in a city your unit is patrolling? Are they looking for protection or to kill? Quite apart from the trauma caused to those whom the child soldiers fight, they themselves may never recover, even if they live. The child mind is so impressionable that any conditioning it receives can be irreversible, making them loyal and obedient even to the most evil and gruesome commands. For these reasons the use of child soldiers is seen as one of the most evil of war crimes, something often reflected in SF where the creators of a child soldier program are attacked after the enemy had been defeated, like Graff in Ender's Game.
In SF the main reason for the use of child soldiers as a regular fighting force seems to be in a war against an alien race. In such situation the speed with which troops can be put on the battlefield is imperative, and so using children or teens is an advantage. They can also be more easily condition, medically and physiologically to cope with the stresses of such a war. the HALO franchise is one of few that depicts a program using children for this reason. The SPARTAN-IIIs were composed of young orphans turned into disposable super soldiers that could be expended against the Covenant. As fatality rates for their missions were often 100% mental conditioning would be central to getting them to fight their hardest, and preventing them from cracking u when they survived with most of their friends dead. This seems to be the most mainstream look at the use of children as a frontline army, and even then they are not the primary fighting force.
Apart from the mental aspects children could also be selected because they cold be bred more quickly. Although it is hard to imagine a situation in which anyone would be desperate enough to breed humans for war, it could arise in an alien invasion. In a SF 'Verse this would explore the absolute hopelessness of a war against a superior enemy, as well as examining highly complexed moral and ethical issues.
For a war in space children are small and lighter. A battalion of child soldiers with weapons and supplies will weigh less and take up less space than a adult force, making them more operationally flexible. Also, less material is used in making their weapons and equipment, vital if resources are running low. For example, if powered armour is used it could contain large amounts of rare earth metals, which are called rare for a reason. Thus the smaller the amount used per soldier the better. A smaller soldier can also hide better, access smaller spaces, and is harder to hit in combat.
But why would you write about this? One reason that the theme of a child army is so little seen as opposed to a single child hero is that it is a very terrible thing, one which none is comfortable even thinking about, especially as it is going on in the world today. It is not something that should be included in a SF 'Verse for 'shits 'n giggles', it should have a purpose. Outside of the main story arch it can denote a truly evil faction in a war, or one that is terrible desperate to win. Within the main story it can be used to explore the these of identity; do we have to loose our humanity to defeat the aliens kind of scenario. However it is used, its inclusion in a SF 'Verse will have great impact, and could make an apocalyptic story far darker than the usual run of the mill. The most interesting focus would be not the child soldiers, but the adults who created them struggling to accept what they have done.