An immigrant rights group alleges that Hernandez acted illegally when he asked a deputy to take away from his court a Mexican-born man who was later detained by federal immigration authorities.

BILLINGS, Mont. — An immigrant rights group alleged Monday that a Montana judge acted illegally when he asked a deputy to take away from his court a Mexican-born man who was later detained by federal immigration authorities.

Miguel Angel Reynaga Hernandez, a 40-year-old construction worker living in the city of Billings, was detained in October after appearing in court with his wife, who was seeking a civil protection order against another person.

The Northwest Immigrant Rights Project contends that former Yellowstone County Justice of the Peace Pedro Hernandez had no authority to initiate Reynaga’s arrest.

The group on Friday sued the judge and Yellowstone County sheriff’s Deputy Derrek Skinner on Reynaga’s behalf in federal court.

“If a county or city sticks its nose into federal immigration matters, they are going to be held liable,” said Matt Adams, an attorney with the Seattle-based group. “Their job is to serve the community, not to help out their federal immigration authority buddies.”

Local law enforcement agencies have turned over suspects to federal immigration officials, which President Donald Trump has encouraged, but Adams said Reynaga’s case is the first he knows of where a judge initiated such a move.

Advocates and judges elsewhere have asked federal officials not to track immigrants at state courthouses, saying it can make victims and witnesses afraid to appear for hearings.

Hernandez, who retired in November after more than 40 years on the bench, said Monday that he had not been served with the lawsuit.

He told The Associated Press that he remembered the case and had been obligated as a judge to report that Reynaga was in the country illegally.

“When the court is notified that something’s illegal, we are supposed to notify authorities,” Hernandez said. “That’s the function of the court.”

Skinner, the deputy, could not be reached immediately for comment.

Some places in the U.S. have “sanctuary” policies that prevent cooperation with detention requests from federal immigration authorities, but none are in Montana.

Reynaga was arrested just outside Hernandez’s courtroom and taken to the local jail before being turned over to federal officials, according to the lawsuit.It seeks unspecified damages for emotional and economic harm that Reynaga suffered as a result of being detained for three months.

It also asks the court to declare that the deputy and judge were not authorized to detain Reynaga solely for being suspected of living in the country illegally.

Deportation proceedings against Reynaga were dismissed last month for “good cause,” according to an order from Immigration Judge John Odell in Tacoma, Washington.

Adams said the dismissal was based on Reynaga’s unlawful arrest but that could not be immediately verified.