Mr Justice McCloskey held that, in suitable cases, social needs should be met within a reasonable time.
The verdict has implications for more than 130 people with learning disabilities waiting to be resettled.
Campaigners said the decision was an important legal victory for long-stay hospital patients.
The case was taken by lawyers for an unidentified man who spent 11 years at Muckamore Abbey in Antrim as a voluntary patient.
Judicial review proceedings were brought due to the length of time patients had to wait to be discharged from the hospital.
People with learning disabilities were supposed to be treated in the community by 2013, but that target has been moved to 2015.
Even if they have been found ready for release, patients are not allowed out unless suitable accommodation with adequate support for their learning disabilities is available.
In 2011, a judge rejected all grounds of challenge, but after an appeal, the case was sent to the High Court so the Department of Health’s own “people first guidance” could be examined.
Ruling on proceedings against the department and the Belfast Health and Social Care Trust, Mr Justice McCloskey declared there was a “duty to assess” those who might qualify for community care benefits.
He also held that the people first guidance created a “legitimate expectation” that once an evaluation had been undertaken, the authorities were under a duty to provide any care within a reasonable time.
The case was brought by the Law Centre (NI) on behalf of the former Muckamore patient.
The Law Centre’s Les Allamby said the judgment clearly established an obligation on the department and the trust to regularly complete an assessment of need for all those who require community care services in Northern Ireland.
“The ruling in this case should ensure that no-one should remain forgotten by the health and social care system,” he said.
“We believe that with the right support people in Muckamore Hospital can live independently in the community.”
Maureen Piggott, director of Mencap in Northern Ireland, said the verdict would help ensure proper future assessment of the needs of people with a learning disability.
“It strengthens the position of those who are still waiting to move out of learning disability hospitals, but also those who need additional support to live with their family, or in their own homes in the community,” she said.
By BBC News