He was just a 14-year-old schoolboy when the Islamic State of Iraq and al-Sham (ISIS) took over his city, Mosul, in northern Iraq. His school soon shut down. With little else to do, he said, he joined ISIS to make money. He said he received twenty days of training, and then worked as a cook, making about $50 a month. “I never wanted to fight,” he said. “That’s why I stayed a cook.”

Kurdish security forces in northern Iraq captured him during a military offensive in the fall of 2016, and detained and interrogated him. Last year, a Kurdish court convicted him of terrorism. When a colleague and I met him in November in a reformatory in Erbil, he had been in prison for more than two years.

With the rise of violent extremist groups like ISIS, al Qaeda, al-Shabab, and Boko Haram, many countries have adopted much more aggressive counterterrorism measures, including a marked increase in the detention and prosecution of children. The United Nations has documented a five-fold increase in the number of children detained in the context of armed conflict since 2012.

These practices have created an unfair and dangerous double standard: in “traditional” armed conflicts, child soldiers are seen primarily as victims who need rehabilitation assistance and help reintegrating into society. But in a conflict with a so-called terrorist group, children are prosecuted as criminals and sentenced to prison as terrorists.

If the boy from Mosul had been part of an armed group in Colombia, the Democratic Republic of the Congo, or any number of other conflict countries around the world, he might be back in school or getting vocational training. In the past twenty years, tens of thousands of former child soldiers have benefited from rehabilitation programs designed to help them rejoin society. These programs recognize that recruiting children for armed conflict is a violation of international law and that the primary violators of the law are the adult recruiters, not the children.

When it comes to ISIS, however, children who have been involved with the group in any capacity are increasingly being treated as criminals and charged with terrorism. The situation is particularly dire in Iraq, where the government of Iraq and the Kurdistan Regional Government (KRG) are currently detaining an estimated 1,500 children for alleged ISIS involvement. A child may be arrested simply because someone from their village reported them—rightly or wrongly—as connected to ISIS. One father told us about the arrest of his 14-year old son: “People said they had seen him with ISIS. He was hanging out with them because they were his friends and his cousins, that’s it.”

Once a child is arrested, security forces can torture him to coerce confessions.  Late last year, a colleague and I interviewed twenty-nine boys who had been detained as ISIS suspects in Iraqi Kurdistan. Nineteen described abuse that amounts to torture. They said that interrogators beat them with plastic pipes, electric cables, or rods, sometimes for hours. Some said they were given electric shocks or tied into painful positions.

Their interrogators didn’t seem to care whether they were really part of ISIS. One 17-year-old told me his interrogators said, “You need to say you were with ISIS. Even if you weren’t, you need to say it.” All but one of the boys we interviewed said they eventually confessed to ISIS association, believing they had no other choice. One 16-year-old boy told us, “My confession says that I joined ISIS for sixteen days, but actually, I didn’t join at all. I said sixteen days to stop the torture.”

Over the past twenty years, I’ve interviewed scores of child soldiers from UgandaSri LankaNepalMyanmar, and other conflicts. Some were recruited by force, while others joined armed groups or forces to earn money, gain status, to escape family problems, or because they were influenced by friends or relatives. The children I interviewed in Iraq who admitted joining ISIS were no different. Several said they joined ISIS to make money or because their friends had joined. One said he joined “to feel brave and powerful.” Multi-country research by United Nations University has found that contrary to conventional wisdom, ideology is rarely the primary force motivating children’s association with violent extremist groups.

Many of the children I interviewed in Iraq who joined ISIS now express regret. “The only reason we joined is because we were young and didn’t think,” said a 17-year old boy. “We were just kids.” Most said that once they are released from prison, their only desire was to reunite with their families, and go back to school or get jobs.

There’s no doubt that some children have committed terrible crimes during armed conflict. If so, they can be prosecuted under international law, taking their age into account and adhering to international standards. But prosecuting children for any affiliation with ISIS is not justice, and will not help Iraq rebuild its society. On the contrary, it’s likely to only marginalize these children further, and even their families, and foster future grievances.

At the end of the brutal civil war in Sierra Leone, a special court was established to prosecute those most responsible for war crimes during the conflict. The court’s prosecutor, David Crane, announced that as a matter of principle, he would not prosecute children. “I want to prosecute the people who forced thousands of children to commit unspeakable crimes,” he explained.

UNICEF and child-focused agencies such as Save the Children or War Child have years of experience helping children associated with armed groups get back into school and get the rehabilitation help they need. Iraqi and KRG authorities should work with such agencies to set up rehabilitation programs that can help children affiliated with ISIS to reintegrate back into society.

Whether a child soldier gets sent to prison or rehabilitation should not be based on labels or a matter of chance. The recruitment of children by armed groups is always illegal. Prosecutions should focus on the recruiters, not the children. What the children need is help rebuilding their lives.