Massachusetts court 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 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.

"Today's decision is a victory for the rule of law and smart immigration and criminal justice policies, and a rejection of anti-immigrant policies that have stoked fear in communities across the country," Massachusetts Attorney General Maura Healey said. "As my office argued in this case, Massachusetts law protects our residents from illegal detention and prevents the federal government from forcing law enforcement to make decisions contrary to the public safety interests of their community. This decision allows local law enforcement to focus their resources on keeping people safe."

The U.S. Supreme Court has ruled that remaining in the U.S. when subject to deportation is a civil, not a criminal, infraction. In the unanimous decision, 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."

The American Civil Liberties Union of Massachusetts said that based on the court's language, the decision extends to all Massachusetts police officers.

"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 ACLU 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 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 from custody back 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.

Bristol County Sheriff Thomas Hodgson, an outspoken opponent of undocumented immigrants, said he is already working with Republican lawmakers on "a bill that aims to authorize all levels of law enforcement and court officers to cooperate fully with Immigration and Customs Enforcement."

"The decision makes Massachusetts residents and visitors more vulnerable to become victims of crime," Hodgson said of the court ruling.

Rep. James Lyons of Andover, Rep. Shaunna O'Connell of Taunton and Rep. Marc Lombardo of Billerica are working with Hodgson on the legislation.