BOSTON — Massachusetts police officers do not have the authority to arrest someone suspected of being in the U.S. illegally if that person is not facing criminal charges, the state’s highest court ruled Monday.

The Supreme Judicial Court opinion applied specifically to officers who provide security in state courthouses, but the ruling also suggested that no Massachusetts police officer has the legal standing to comply with such federal requests. One of the state’s police associations said the ruling applied to all state law-enforcement officials.

The U.S. Supreme Court has ruled that remaining in the U.S. when subject to deportation is a civil infraction, not a criminal one. In its unanimous decision Monday, the Supreme Judicial Court pointed out there is no state law that provides “authority for Massachusetts court officers to arrest and hold an individual solely on the basis of a federal civil immigration detainer beyond the time that individual would otherwise be entitled to a release from state custody.”

“Conspicuously absent from our common law is any authority (in the absence of a statute) for police officers to arrest generally for civil matters, let alone authority to arrest specifically for federal civil immigration matters,” the court wrote.

The decision is a major setback to the Trump administration’s crackdown on immigration enforcement, the American Civil Liberties Union of Massachusetts said.

“This court decision sets an important precedent that we are a country that upholds the constitution and the rule of law,” Carol Rose, the ACLU’s executive director said. “This victory is the first of its kind in the nation. At a time when the Trump administration is pushing aggressive and discriminatory immigration enforcement policies, Massachusetts is leading nationwide efforts by limiting how state and local law enforcement assist with federal immigration enforcement.”

A spokesman for U.S. Immigration and Customs Enforcement did not immediately respond to a request for comment.

The president of the Massachusetts Major City Chiefs of Police Association says the ruling will be a major shift for police. Brian Kyes, who is also police chief in Chelsea, near Boston, says even those charged with a crime will have to be released after paying bail. In the past, police would often detain them at ICE’s request.

The court’s decision came in the case of Sreynuon Lunn, who in October was arraigned on an unarmed robbery charge in Boston Municipal Court. At the time, the U.S. Department of Homeland Security issued a civil immigration detainer against Lunn, who was born to Cambodian parents.

The state charge was dismissed on Feb. 6, but a judge refused to free him and court officers kept Lunn in a courthouse holding cell until an immigration officer took him into federal custody.

His lawyers appealed, saying in part that his detention based solely on the request by federal officials was unconstitutional.

Lunn, 32, was ordered released by a federal judge in May and remains free in the U.S., the ACLU said.

He has been the subject of a long-running deportation battle.

Lunn was born in a Thai refugee camp to Cambodian parents fleeing the Khmer Rouge and brought to the United States as a 7-month-old. He was legally allowed into the country as a refugee and given lawful permanent resident status. He has two U.S.-born children.

Immigration officials first tried deporting him in 2009 after he was convicted of an aggravated felony. But both Cambodia and Thailand have denied him citizenship and refused to issue travel documents.

The Massachusetts court urged the state Legislature to address the matter.