ICE is accusing Philadelphia city officials and the Police Department of endangering the public. It’s actually more complicated than that.

Twice this year, ICE says, local authorities released an alleged child sexual predator, an undocumented Guatemalan national. They did so despite having been sent ICE detainers asking that the man be held for pickup by the federal immigration enforcement agency. ICE announced on Sunday that it had arrested the man — and had some harsh words for local officials.

“We are seeing politicians put their political agendas above the safety of the citizens they serve,” Simona Flores-Lund, director of the Immigration and Customs Enforcement Philadelphia Field Office, said in a statement. “The victims in this case are young children, whose lives are now forever changed.”

It sounds terrible. But here’s the catch: Last year, Philadelphia, a “sanctuary city” that doesn’t assist federal immigration authorities, won a lawsuit allowing its police officers and other officials to forgo helping ICE. If ICE wants the city to keep a suspect in custody, it needs to present a judicial warrant, and then that person will be held.

“The City of Philadelphia has always cooperated with ICE when that agency goes before a judge and obtains a federal arrest warrant,” Mike Dunn, a spokesperson for Mayor Jim Kenney, said Monday. “This is not burdensome, and ICE has in fact obtained such warrants on several occasions.… We fully comply with federal law. The reality is that the White House has tried to coerce cities like Philadelphia into going beyond federal law.”

What’s this particular case about?

ICE said Hector Moran-Espinoza was arrested April 2 and charged with involuntary deviate sexual intercourse by forcible compulsion, unlawful contact with a minor, and multiple related offenses, including abuse of children by photographing or videotaping sexual acts. He was arrested again on May 9 for sexual offenses including indecent assault of a person under 13. Both times, ICE said, it lodged an immigration detainer, and both times the detainer was not honored.

He was released in April after a woman posted the required 10% in cash of his $150,000 bail, a total of $15,000. Following the May arrest, the same woman posted the same amount of $15,000 cash bail in October.

How could that happen?

Philadelphia is among the jurisdictions that say ICE detainers, which are issued by the agency itself, are not legally valid. The Kenney administration won a federal lawsuit arguing that the city isn’t part of the federal immigration-enforcement machinery and doesn’t have to devote its staff to help ICE do its work. City police officers arrest people who they believe have committed crimes regardless of immigration status, and a judge decides whether and when those people should be released.

The city also worries it could be sued for keeping someone in jail beyond the release date set by a judge.

Has that ever happened?

Yes. Lehigh County and Allentown authorities were successfully sued for keeping a man of Puerto Rican descent in prison — even after he posted bail — so that ICE could investigate whether he was in the country illegally. It turned out that Ernesto Galarza was born in New Jersey. His settlement for three days behind bars totaled $145,000.

What was Philadelphia’s lawsuit about?

The city sued after the Trump administration tried to withhold about $1.5 million in federal law enforcement grant money unless Philadelphia officials agreed to actively assist federal authorities in identifying and turning over undocumented immigrants.

» READ MORE: Appeals court largely upholds Philadelphia win over Trump administration in sanctuary city case

Then what happened?

After almost a year of litigation and a four-day trial, U.S. District Judge Michael Baylson ruled that the Trump administration’s effort to hold back the money “violates statutory and constitutional law.” He found that the city’s refusal to enforce federal immigration laws was based on policies that were reasonable, rational, and equitable.

What exactly is an ICE detainer?

It’s a request to a law enforcement agency to notify ICE in advance of a prisoner’s release and to keep that person in jail until ICE can arrive and take custody. ICE says that’s safer for everyone.

An ICE spokesperson noted on Monday that detainers are submitted with an “administrative warrant” issued by the agency. Immigration advocates, including the Immigrant Legal Resource Center, say an ICE warrant is “not a real warrant” because it is not reviewed by a judge or any neutral party to determine if it is based on probable cause.

Does everyone besides Philadelphia honor those detainers?

No. And it’s a source of frustration to ICE, which says sanctuary policies — embraced by more than 300 cities, counties, and towns across the country — “negatively impact public safety” and leave it no choice but to increase enforcement in neighborhoods and at workplaces.

» READ MORE: ICE announces 5-day sweep nets 45 in Philly region, including convicted child rapist

Does Philadelphia always hold a suspect for ICE when presented with a judicial warrant?

It does. Or at least it tries to. In March, it came to light that the city had wrongly released an undocumented man despite having received a valid judicial warrant. City officials blamed a clerical error. U.S. Attorney William M. McSwain criticized the city government for operating what he called two separate systems of law, one for U.S. citizens and one preferential for undocumented migrants.

Don’t some Pennsylvania jurisdictions cooperate with ICE?

They do. A recent study found 19 counties either had formal contracts with ICE to hold migrants; share jail information; provide jail access to federal agents; supply times that ICE could pick up migrants; had the probation office work with ICE; or wished to pursue a stronger relationship with the agency.

Other jurisdictions, like Bensalem, have considered and rejected alliances with ICE.

The Kenney administration says trust between police officers and immigrant communities is essential to reducing crime and helping victims. “Our policy — which has been upheld by a federal judge — ensures that trust, while still honoring judicial warrants,” Dunn said.