The girl, who is in council care, had been in "urgent need" of a secure placement and was deprived of liberty after an order by a family court judge.
Detail of her plight emerged at a public Court of Appeal hearing in London on Tuesday.
Judge Stephen Wildblood had initially considered the case at a private family court hearing.
He had ruled that the council with responsibility for the teenager's care, and two social work managers, could be named in media reports of the case.
But three appeal judges have overturned that ruling after council bosses, and the social work managers, mounted a challenge.
Other parties involved in the case, who include a guardian appointed to represent the teenager and a hospital trust, agreed to Judge Wildblood's ruling being overturned.
Sir Andrew McFarlane, the president of the Family Division of the High Court and the most senior family court judge in England and Wales, Lady Justice King and Lord Justice Warby, ruled that Judge Wildblood should reconsider arguments about naming.
Appeal judges said only a limited amount of detail about the case could be revealed.
A number of judges have raised concern about a shortage of secure accommodation for troubled children in recent years.
In July 2021, one of Britain's most senior judges described a lack of "proper provision" for children who require approved secure accommodation as "scandalous".
Supreme Court justice Lord Stephens said the problem was a scandal with "all the ingredients for a tragedy".
He outlined his thoughts in a Supreme Court ruling on a case concerning another vulnerable teenager.
In August, this year, a High Court judge described a shortage of secure accommodation for troubled children in England and Wales as a "national scandal".
Mr Justice Francis, who is based in the Family Division of the High Court, had been considering a case centred on a teenage girl in council care in Wales.
He said children with behavioural difficulties in "crisis" situations were not being "properly provided for".
A lawyer representing the council involved had told Mr Justice Francis that in mid-August, 62 children in England and Wales were in need of a secure placement, but "only two" places were available.