A teenager who was a risk to himself and the public could not be found a secure mental health bed for a month in England, Scotland or Wales, his father claims.
Secure accommodation was sought for Boy Y, from Norfolk, in July but none was available.
Mr Justice Holman, who ruled on an injunction over the case, said the lack of secure beds was “scandalous”.
NHS England said improving mental health care was an “absolute priority”.
Boy Y, whose identity cannot be revealed for legal reasons, suffers mental health problems and in the summer of 2016 his father believed he was a “danger to himself and the public”.
In response, Boy Y was sent by Norfolk County Council – responsible for his care – hundreds of miles away to a secure unit in Scotland.
In July this year, he was moved to “a non-secure residential placement in Scotland” even though at the time his “psychological health” was a “concern”, the boy’s father told the BBC.
He said his son “absconded two to three times” from the non-secure unit he was moved too.
“The first time he got out, he went to a party with a load of the local hoodlums and ended up taking drugs,” said his father.
Eleven days later, the council decided he should go back to a secure unit.
But by then, his bed had gone and his father was told none for adolescents were available in England, Scotland or Wales.
The council’s director of children’s services Matt Dunkley, said: “The lack of secure and specialist beds for children is a national issue, which has received widespread publicity in recent weeks.
“While we cannot comment on any individual child in detail, we are aware of the vulnerability of children with these needs and will do all we can to provide safe care for them.
We have worked around the clock to find suitable accommodation for this young man and now have a secure, supportive placement arranged that we believe will safely meet his needs.”
In August, his father said the council told him “they can’t put a chain around him… they can’t lock him up because they have nowhere to put him”.
Mr Justice Holman, speaking after an injunction brought by Norfolk County Council was amended to allow the BBC to report on the case, said: “The extreme shortage of secure accommodation is scandalous.”
The council had said it “originally sought an injunction to protect the identity and interests of the young person and their wellbeing”.
In a statement, NHS England said improving young people’s mental health was “an absolute priority”.
“Although transformation won’t happen overnight, work is well under way to make sure the right care is available at home or as close to home as possible,” it said.