Justice Sullivan's ruling means that long-term psychiatric patients discharged into residential care need no longer cover any part of the costs of their accommodation.
The judge outlawed the practise of about half of England and Wales's local authorities which charge such patients for the cost of their care, according to their means.
The court heard there is also the prospect that councils may have to backdate some of those costs to the date when the 1983 Mental Health Act came into force.
'It means an annual figure of not less than£50m per annum, which could have a potential for catastrophe in the local authority budgets for the half of those affected.'
He said the case had been brought to court on an issue of legal principle and a 'matter of national significance' which needed to be resolved by a judge.
The case was brought by four long-term mental illness sufferers who said their councils had no right to charge them for 'residential after-care' following discharge from hospital.
The councils involved in the case were: Redcar and Cleveland BC, Richmond LBC, Manchester City Council and Harrow LBC.
The judge said one of the four individuals involved in the case, a man aged 28, from Cleveland, had been detained under the Mental Health Act in 1995 after falling ill while studying for a doctorate at Cambridge University.
He was later diagnosd as suffering from schizophrenia and a form of 'obsessive compulsive disorder' possibly linked to autism.
He is now living at a residential care home where Redcar and Cleveland BC had, until today's ruling, required him to pay£114 a week towards his accommodation costs.
A 67-year-old woman from Richmond had been diagnosed with dementia after an operation to remove a brain tumour in 1994. She now lives at a care home in Weybridge, Surrey.
A man, aged 34, from Manchester, who has a long history of mental health problems and who has been described as 'a revolving door patient' had also been required to contribute towards the costs of his care at a home in the city.
Since his discharge in hospital in 1996, he has so far contributed more than£15,000 towards the costs of his after-care.
A woman from Harrow, aged 69, who also has a long history of mental health problems, had been admitted many times to mental hospitals under the Mental Health Act.
She was discharged under supervision in September 1997 and now lives at a care home in north London.
Justice Sullivan upheld arguments by lawyers for the four that s117 of the Mental Health Act obliges councils to fund residental after-care for long-term mental patients after their discharge from hospital.
'They are under a duty to provide the applicants with residential accommodation as part of their after-care under s117, and may not provide such accommodation and charge for it,' he told the court.
'I can see no inherent unfairness in such a group being entitled to free accommodation as part of the package of after-care in the community.
'The underlying policy is that those suffering from mental illness should, if at all possible, be cared for within the community and not detained - as they used to be perhaps for many years - in large psychiatric hospitals.'
The judge gave the four local authorities permission to appeal against his ruling.
He told the court: 'I am of the view that there is an issue here which in the public interest should be examined by the court of appeal because it does raise a question of very considerable public interest and questions of public policy.'
After the ruling, Gary Hogan, solicitor for the former mental patient from Manchester, said: 'I think at last we're seeing care in the community meaning something.'