The UN says tens of thousands of Islamic State (IS) fighters and family members being held in Iraq and Syria must be tried or released.
Human rights chief Michelle Bachelet also called on countries to take responsibility for their citizens and take them back if not charged.
The last IS strongholds fell in March and some 55,000 people are being held, including thousands of foreigners.
But many nations have shown reluctance to bring their citizens back.
The countries fear prosecutions of IS fighters may be difficult and public opinion is often strongly against repatriation.
Some countries have also refused to recognise the children of IS members born in Syria and Iraq as citizens, despite their parents having nationality.
Ms Bachelet said that children in particular had suffered “grievous violations” of their human rights.
The UN High Commissioner for Human Rights said there should be no doubt about what must happen to those being detained.
“Accountability through fair trials protects societies from future radicalisation and violence,” she said, adding that continuing to detain individuals not suspected of crimes was not acceptable.
She added: “Foreign family members should be repatriated, unless they are to be prosecuted for crimes in accordance with international standards.”
Ms Bachelet highlighted in particular the plight of children born to IS fighters, reported to number about 29,000.
“States should provide the same access to nationality for children born to their nationals in conflict zones as is otherwise applicable.
“To inflict statelessness on children who have already suffered so much is an act of irresponsible cruelty,” she said.
A vast number are at al-Hol camp in north-eastern Syria, which has seen a huge increase since the collapse of the last IS strongholds in Syria.
About 1,000 foreign IS fighters were captured by the US-backed Syrian Democratic Forces but several hundred have already been transferred to Iraq for trial. Those remaining are mostly family members.
The UN says there are about 29,000 children of foreign IS fighters in Syria, 20,000 of them from Iraq, but overall there are about 50 nationalities.
France, Russia, Morocco, Saudi Arabia and the Netherlands have taken back some children. Australia also confirmed it had evacuated six children from a “bleak and complicated” situation at a Syrian refugee camp. –BBC