“It forces them to go to inconvenient and costly routes to get to their target,” Mr. Chishti said.

New York’s detainer law, however, has exceptions: The police must turn over a person convicted of one of 170 serious crimes within the last five years — including arson, homicide, rape or robbery — and in cases in which a judge has signed a detainer request.

ICE issued 1,526 detainer requests to the New York Police Department in the 2017 fiscal year, up from 80 in 2016. The Police Department complied with none of them.

By its own policy, ICE does not enter places of worship, schools and hospitals. But courthouses have become frequent sites of arrests because they offer a degree of control that agents would not have when going to people’s homes.

“Because courthouse visitors are typically screened upon entry to search for weapons and other contraband, the safety risks for the arresting officers and for the arrestee inside such a facility are substantially diminished,” ICE said in a statement.

According to the Immigrant Defense Project, a nonprofit organization that is tracking arrests at city and state courthouses, 87 arrests were made in New York City courts in 2017, compared with six in 2016. So far, this year, there have been 13 courthouse arrests.

Aboubacar Dembele, 27, was one. He was surrounded by immigration agents moments after stepping out of a hearing in Bronx Criminal Court. Mr. Dembele, an undocumented immigrant from the Ivory Coast, had pleaded not guilty to an assault charge stemming from a fight on a city bus in December; the judge had reduced the charge to a misdemeanor from a felony, and had set a follow-up court date to address the charges.