A mother is suing a Welsh council after a judge ruled the authority had acted unlawfully by keeping a nine-year-old boy in foster care.
The child was placed in care by Anglesey council while his mother was receiving psychiatric treatment.
But when she was allowed home, social workers refused to let her son return.
The boy and mother have now been reunited after a judge said the council had failed to follow legal procedures.
On Monday the family's lawyer Frances Jones said the child had been returned to his mother immediately after the injunction was granted.
She said: "As the mother's solicitor I am delighted to have played a part in bringing the child home.
"We are now continuing with the claim for damages."
The hearing into the case took place several weeks ago at the family division of the High Court, which was sitting in Mold.
'Not above law'
The judge said he wanted lessons to be learned from his judgement in the case, with transcripts of the hearings now released revealing the full details of what happened.
The court was told how the child had been taken to hospital with pneumonia in March last year, and the mother had a short stay in a psychiatric ward.
On release from hospital the boy was placed in foster care.
But when his mother was also released from medical care, social services refused requests for her son to come home.
The boy spent five months in foster care.
Judge Jones said the council should have applied for care orders as soon as the mother made it clear she wanted her son back.
"By failing to do so, they were essentially maintaining an unlawful position," said Judge Jones. "The social services department of Ynys Mon Council in that respect, it seems to me, were acting beyond the proper control of that local authority's legal department."
The judge added: "Social services are not above the law and they, like everybody else, is subject to it."
He also told the hearing that he had previously voiced his concern about a health board case which involved Anglesey council.
Judge Jones said: "I have a suspicion, and it is only a suspicion, that this local authority may have fallen into the temptation of withholding the commencement of public proceedings for reasons of economy. I hope very much that this is not a correct suspicion.
"If that suspicion was well founded, that to my mind would be wholly unacceptable."
The judge said that the authority needed to carry out an urgent review of its internal procedures.
A spokesperson for Anglesey council said: "Due to ongoing legal considerations, we are not in a position to comment on this matter."