Two 15-year-old girls had to spend four nights in police cells because Child, Youth and Family didn't have enough beds available at its youth justice facility.
Judge Lisa Tremewan called the situation completely unacceptable and, when the case was called at the Waitakere Youth Court on Tuesday morning, said she would not be remanding the girls in police custody for a fifth night.
The judge said the girls were arrested on Friday and face charges of driving while suspended and failing to stop for police. One is also alledged to have assaulted a police officer.
Judge Tremewan said not only was it inappropriate for the girls to be in custody, but it was also wrong to expect police to look after young people in the cells.
However, after the judge made her views known to Child, Youth and Family the government agency charged with looking after the country's most vulnerable youth managed to find two beds in the secure wing of their South Auckland youth facility.
Brenda Donald, the lawyer for one of the girls, told Radio New Zealand's Checkpoint programme on Tuesday that police did their best for them under trying circumstances in cells meant for overnight arrests - not made for children for four nights.
"They're just for people coming in overnight and going to court the next morning. So to have young people aged 15 in the cells for four nights is, as the judge said, totally inappropriate."
Helen Bowen, the lawyer for the other girl, says media attention to the case may have helped Child, Youth and Family find beds for the girls. Ms Bowen told Checkpoint there clearly aren't enough such beds available and she has in the past had to use pressure from the media to get the agency to act.
Child, Youth and Family has 156 beds, split between boys and girls, available for youth offenders throughout the country.
General manager for youth justice support Chris Polaschek said when the girls were arrested all of the beds were taken.
Mr Polaschek described the situation as a blow-out, but said it does happen on the rare occasion.
Listen to Checkpoint interview with Brenda Donald
Listen to Checkpoint interview with Helen Bowen