Massachusetts' highest court ruled Monday that local law enforcement officials do not have the authority, under state law, to detain a person based solely on a request from federal immigration authorities.

The landmark decision by the Supreme Judicial Court was hailed by immigrant activists and state Attorney General Maura Healey, who called it "a victory for the rule of law."

In ruling on the Lunn v. Commonwealth case, the high court concluded that state law "provides no 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 the individual would otherwise be entitled to be released from State custody."

The detainer is a request from U.S. Immigration and Customs Enforcement (ICE) to hold a person in custody whose criminal proceedings have been settled and who is otherwise free to go. This could mean the individual's charges have been dismissed, they've posted bail, or their jail sentence has been completed.

The detainer -- which is not the same as an arrest warrant, which requires proof of probable cause and a judge's signature -- gives ICE up to two days to look into a person's immigration status and potentially pursue deportation.

“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," Healey said in a statement. She added that the ruling "allows local law enforcement to focus their resources on keeping people safe."

C.M. Cronen, who's the ICE field office director in Boston, disagrees.

In a statement, he said the ruling "weakens local law enforcement agencies’ ability to protect their communities." Cronen added that ICE is reviewing the decision to determine next steps.

U.S. Attorney General Jeff Sessions, the nation's top law enforcement officer, has argued that detainers give federal immigration officials a chance to investigate a person's immigration status while keeping criminals off the streets.

And Bristol County Sheriff Thomas Hodgson, who takes a hard line on immigration enforcement, said the "decision makes Massachusetts residents and visitors more vulnerable to become victims of crime."

But Emma Winger, an attorney who represented Lunn before the SJC, said that concerns about public safety are not relevant.

"Detainers only apply to folks who have, for example, been found not guilty, or their case has been dismissed, or a judge has determined they should be released on bail," Winger said. "So, this case doesn't in any way threaten the public safety of Massachusetts residents."

The SJC's decision explained how Sreynoun Lunn, who was first ordered deported back in 2008, came to be at the center of this case:

Lunn was arraigned in the Boston Municipal Court on October 24, 2016, on a single count of unarmed robbery. The day before the arraignment, the United States Department of Homeland Security ... issued a civil immigration detainer against him. The detainer document ... requested, among other things, that the Massachusetts authorities continue to hold Lunn in State custody for up to two days after he would otherwise be released, in order to give officers of the department time to arrive and take him into Federal custody.

Lunn has been in federal immigration custody several times since 2008. He was most recently held as a result of the ICE detainer mentioned in the SJC's decision. He remained in custody for more than three months as immigration officials attempted to deport him.

However, because Lunn was born to Cambodian parents in a Thai refugee camp, neither nation recognizes him as a citizen. Both nations have refused to take him, preventing the U.S. from deporting him to either place.

Lunn, who's 32, was then released from federal custody in June after lawyers argued he was being held without due process.

Eva Millona, director of the Massachusetts Immigrant and Refugee Advocacy Coalition, said Monday's ruling "provides much needed clarity for Massachusetts law enforcement."

That was echoed by Chelsea Police Chief Brian Kyes.

"In the event that we get an ICE detainer -- which right now we've been getting at least one a week, if not two a week ... the detainer will be filed with the arrestee's folder, their file that goes over the court," Kyes said. "But in the event that the individual is in fact bailed and we do receive a detainer, the individual is going to be bailed."

Bristol Sheriff Hodgson says he's teaming up with several state representatives to draft new legislation in response. James Lyons, a Republican state representative from Andover, says he's hoping to get a new statute on the books.

"My role as a legislator is to put before the Legislature language that will allow police officers to arrest people who are found to be in violation of immigration laws and in fact have a civil immigration detainer outstanding against them," he said.

Lyons and his co-sponsors hope to file the new bill this week.

But for now, the SJC's decision is the law statewide.

Susan Church, a former head of the New England chapter of the American Immigration Lawyers Association, says this Massachusetts ruling could provide a roadmap for other states.

"This is hopefully something that we will look back on and see that it sent a message out to all the other states that this is not the job of the states, to be enforcing federal immigration laws," she said.

With additional reporting by WBUR's Benjamin Swasey and the Newscast Unit