Immigration and Customs Enforcement policy prohibits agents from arresting people in certain “sensitive locations,” including hospitals and schools, to preserve the public trust. But in January 2018, the then-acting director of ICE, Thomas D. Homan, issued a directive clearing the path for agents to make arrests in courthouses.

The memo said that courthouses were a safer place to confront immigrants than homes or workplaces because people were screened for weapons before they enter.

The decision touched off an angry response among some in law enforcement, who said ICE arrests at courthouses could lead some immigrants to avoid the entire justice system.

“If you’re afraid to come forward out of fear of being swept up and deported, how many heinous crimes will go unreported?” said Craig D. Apple Sr., the sheriff of Albany County. “If people are afraid to come to me and speak with me, then we have a problem.”

ICE officials said their agents turn to courthouses only as a last resort, especially in sanctuary cities where law enforcement officers have declined to cooperate with immigration authorities.

“Absent a viable address for a residence or place of employment, a courthouse may afford the most likely opportunity to locate a target and take him or her into custody,” Rachael Yong Yow, an ICE spokeswoman, said in a statement.

The New York State Office of Court Administration, which governs court procedures in the state, instituted new rules in April prohibiting immigration agents from arresting migrants in courthouses without a warrant signed by a judge. The rules do not apply to local courts, which operate outside of O.C.A. control.