Although the council admitted there had been 'an unacceptable delay' in dealing with the girl's urgent needs, the president of the high court family division, Sir Stephen Brown, said it would be 'inappropriate' for the court to declare the local authority in breach of its duties under the Children Act.
The court heard the girl is the daughter of schizophrenic parents who could not cope with her. She was adopted aged two in 1983, but in November 1992 her adoptive father, to whom she was very close, died of cancer.
She began to suffer serious psychiatric problems and was compulsorily admitted to a mental clinic in June 1995 and has been there ever since.
He said experts agreed that the girl could not go back to live with her adoptive mother or be placed in a children's home.
The council had been trying to find specialist foster parents for her, 'but unhappily none has been found'.
When Christmas 1996 came and went and there seemed no end to her detention, the judge said the girl 'became violent and suffered great distress.'
Mr Ian Wise, for the girl, had asked the judge to make a formal declaration that the city council was in breach of its Children Act duty to provide appropriately 'and expeditiously' for the girl's accommodation and care needs.
He told the judge: 'We say the local authority should have found a solution to this girl's problems long ago. The delay has been so enormous that it does amount to an error of law on the council's part. The council has failed to act with due diligence.'
He claimed that only judicial review proceedings had 'concentrated the mind' of the local authority and galvanised it into action.
But Mr Roger McCarthy QC, for Birmingham city council, said the authority was 'facing a terrible dilemma' although it recognised that the girl's continued stay in the mental clinic was causing her 'the gravest distress'.
The council had to strike 'a very difficult balance' between the girl's sufferings and the need to ensure that she was placed with the right foster carers.
He told the judge the council had recently come up with foster parents who might be willing to accept the girl, adding: 'It's a terribly sad situation, but there is now some real prospect of a solution for this young lady in the very near future'.
'This is a solution which the council will pursue to the utmost,' he added.
Sir Stephen told the court: 'There has been unacceptable delay here, that seems to be acknowledged.
But he added: 'I don't think anyone can say at this moment what the right solution is for this girl; it is a very complex matter'.
Without hearing evidence it was impossible 'to reproduce in any sufficient detail the difficulties which confronted the authority,'
Although the girl's judicial review challenge had perhaps served to force the city council into action, the judge said it would be counter-productive for the court to declare the council in breach of its statutory duties.