A federal judge in California has ordered immigration courts in three states to provide legal representation for immigrants with mental disabilities who are in detention and facing deportation, if they cannot represent themselves. The decision is the first time a court has required the government to provide legal assistance for any group of people before the nation’s immigration courts.

The ruling by Judge Dolly M. Gee, of federal court for the Central District of California, in Los Angeles, was handed down late Tuesday in a class-action lawsuit brought in 2010 by the American Civil Liberties Union, among other groups. One plaintiff in the case is José Antonio Franco González, 33, an immigrant who was detained for more than five years after his deportation case was closed, because severe mental retardation prevented him from arguing for himself in court or even understanding his situation.

On Monday, federal immigration officials issued a new policy that would, in practice, expand the California ruling nationwide, making government-paid legal representation available to people with mental disabilities in immigration courts in every state. The release of that policy indicates that the Justice Department, which runs the immigration courts, broadly accepts the approach ordered by Judge Gee.

The new practice is an unprecedented expansion of protections for people appearing before the immigration courts, lawyers and federal officials said. Unlike in the criminal courts, immigrants facing deportation or other proceedings do not have a right to a lawyer provided by the government, if they cannot afford to pay for one. Children, including those who are not accompanied by family members, and people with mental disabilities must represent themselves to fight deportation before immigration judges if they do not have private lawyers.