Two teens arrested last week on charges stemming from a horrific killing in Maryland were supposed to be deported last year, but local authorities didn’t turn them over to ICE, the immigration agency said Tuesday.

Prosecutors say the teens, Josue Rafael Fuentes-Ponce, 16, and Joel Ernesto Escobar, 17 — suspected of being MS-13 gang members — feared they would be ratted out for an April robbery, so they and an accomplice snuffed out a 14-year-old suspected snitch. They made her strip before beating her with a baseball bat and chopping her with a machete.

The girl’s body was found in a creek this month.

U.S. Immigration and Customs Enforcement, in a pointed statement Tuesday, said the crime could have been averted but for Prince George’s County’s sanctuary city policy.

Mr. Fuentes-Ponce and Mr. Escobar were in county custody last year on attempted murder charges for another crime. ICE placed a detainer on them, asking to be notified when they would be released so agents could deport them.

ICE said the Prince George’s County Department of Corrections defied the request.

“These individuals had demonstrated violent criminal behavior before, and because they were released in spite of the lawful detainer, they were afforded an opportunity to take a life,” said Diane Witte, director of Baltimore’s ICE field office.

ICE has placed new detainers for both teens after the murder charges.

Prince George’s corrections spokesman Andrew Cephas said the agency didn’t release the teens into the community. He said the corrections department did have custody last year but remanded the teens to Cheltenham Youth Detention Center, a state facility, after a judge’s ruling.

“Neither of these individuals were released to the public from the Prince George’s County Department of Corrections. They remained detained in the juvenile facility until the disposition of their cases earlier this year,” Mr. Cephas said.

He said the county department does inform ICE about upcoming releases but did not provide notification in this case because the two were no longer in the county’s custody.

ICE says the county should have given notification of any transfer out of custody so the agency could lodge a detainer with the new prison or jail.

Under a 2014 Department of Corrections policy, county jails say they will notify ICE of impending releases but won’t hold migrants for pickup unless ICE has a signed warrant from a judge.

Mark Krikorian, executive director of the Center for Immigration Studies, which advocates for stricter immigration controls, said the teens are at the center of several raging immigration debates.

Mr. Fuentes-Ponce came to the U.S. in late 2015 as part of the surge of families from Central America who have overwhelmed the border in recent years.

Under the Obama administration, the family was paroled into the U.S. to await its immigration case. Like many other families, Mr. Fuentes-Ponce didn’t appear for his hearing and was ordered deported in absentia, ICE said.

Mr. Escobar, meanwhile, entered the U.S. in 2016 as an unaccompanied alien child, the other major demographic in the border surge.

Under the law, unaccompanied alien children are quickly sent from Homeland Security to the Health and Human Services Department, which then places them with sponsors. In Mr. Escobar’s case, he was released to a relative living in the District of Columbia area, ICE said.

President Trump and congressional Republicans have called for changes to those laws and policies to allow children to be returned to their home countries quickly, and to allow the families to be detained while their cases are proceeding. If that happened in Mr. Fuentes-Ponce’s case, he would have been removed in 2017 — a year before the first attempted murder charges and two years before the new murder charge.

Mr. Krikorian wondered whether the killing of the 14-year-old girl would receive as much attention as the death of an illegal immigrant teen in Border Patrol custody this week. That case prompted reporters to question Mr. Trump about what steps he would take.

“The anti-borders activists are quick to blame the Border Patrol for deaths that are out of its control, but rationalizes the crimes committed by people who would be removed if the law were enforced. There really is a double-standard here,” Mr. Krikorian said.

The D.C. area has long had a large Central American population, making it one of the top destinations for families and unaccompanied alien children involved in the surge. Prince George’s, Fairfax and Montgomery counties are among the top 10 locations.

More than 5,660 unaccompanied alien children have been placed with sponsors in Prince George’s over the past five years, topping Fairfax at about 5,200 and Montgomery at about 4,300.

The unaccompanied alien children have strained schools and, security experts say, created a breeding ground for gang recruitment.

“Most of the Central Americans coming across the border are not criminals, but gangs have used this flow of people across the border to bring their members into the U.S., and others who weren’t gang members in Central America have become gang members here,” Mr. Krikorian said.