LOS ANGELES — A federal judge has ruled that the government must provide mental health services to thousands of migrant parents and children who experienced psychological harm as a result of the Trump administration’s practice of separating families.

The decision, issued late Tuesday, marks a rare instance of the government being held legally accountable for mental trauma brought about by its policies — in this case, border security measures that locked thousands of migrant parents in detention while their children were placed in government shelters or foster homes.

“This is truly groundbreaking,” Erwin Chemerinsky, dean of the University of California Berkeley School of Law, said of the decision. “The court is recognizing that when a government creates a danger that inflicts trauma, the government is responsible for providing a solution. It is not something I have seen a court do before.”

Judge John A. Kronstadt of the United States District Court in Los Angeles ordered the federal government to immediately make available mental health screenings and treatment to thousands of families forcibly separated under the policy, which was primarily carried out in 2017 and 2018 — though hundreds of similar separations still occur.