SAN FRANCISCO — Five times, the man accused of killing former Pleasanton resident Kate Steinle was deported to Mexico. Five times he returned.

But the efforts of federal immigration officials to detain Francisco Sanchez for a sixth time failed when they turned him over to San Francisco officials, who released him in mid-April. Ten weeks later, Steinle was dead on Pier 14 and Sanchez, 45, a habitual felon, had been arrested for the shooting.

Sheriff’s officials let Sanchez go after drug charges against him were dismissed. San Francisco, a “sanctuary city,” refuses to enforce federal immigration holds. And as news of his circumstances broke, that pro-immigrant policy — shared by many other cities — became embroiled in controversy once again.

In this case, officials with federal Immigration and Customs Enforcement asked to be notified if Sanchez was released so they could take him back into custody, but the city did not do so, said agency spokeswoman Virginia Kice.

“The detainer was not honored,” she said.

San Francisco officials say ICE could have issued a warrant or obtained a court order to keep Sanchez in custody.

The circumstances leading to Sanchez’s release began the day after he was handed over to the sheriff’s department. On March 27, a San Francisco Superior Court judge dismissed charges of possession and distribution of marijuana against Sanchez for reasons that were not clear Friday. He was held in jail for two more weeks, according to Freya Horne, legal counsel for the San Francisco Sheriff’s Office. During that time, Horne said sheriff’s deputies checked with federal prison officials to ensure that Sanchez did not have any holds for any other crimes he may have committed, or for any immigration violations. None came up in the prison system, she said.

So, Sanchez, who is a citizen of Mexico, was released on April 15.

“They are well aware of our policy, and it’s a policy that is being adopted by municipalities across the state and the country,” Horne said.

ICE officials could have “easily issued a court order,” Horne said. She added that sheriff’s officials had “no legal basis” to hold Sanchez after his case was dismissed.

Friday’s revelation about Sanchez’s past has sparked new debate about whether sanctuary cities work in the best interest of the public’s safety. Among the Bay Area’s sanctuary cities are San Jose, Oakland and Berkeley.

Some say holding inmates based solely on their immigration status can create hostility between immigrant communities and police, while others believe local, state and federal authorities should re-examine their policies on releasing illegal immigrants, particularly when those people have a criminal past.

Julie Meyers Wood, who was director of ICE between 2006 and 2008, described the current system as a “real mess right now.”

“As much as it should be a cooperation with regards to immigration, it’s just not working right now. We need to come up with a coordinated strategy, get politics out of it and get public safety at the top,” she said. “It may not be exactly what ICE wants or what San Francisco wants, but it would be a heck of a step forward.”

Sanchez had seven past felony convictions, four of which involved drug charges. Officials did not release any further details on any of the felonies.

Sanchez was arrested about 20 minutes after the 6 p.m. shooting. He was found about a mile south of Pier 14, where Steinle, 32, was walking with her father and a family friend. Steinle, who had just moved to San Francisco and grew up in Pleasanton, was shot in the back.

The killing, police said, appeared to be random. The gunshot pierced Steinle’s aorta, her mother said, and Jim Steinle, the woman’s father, tried to give her CPR as she lay wounded on the ground.

“She said, ‘Dad, help me, help me,” said Liz Sullivan, Steinle’s mother, when reached by phone. “She was so young. This is just like a bad dream.”

Steinle was rushed to San Francisco General Hospital where she later died.

Contact Katie Nelson at 408-920-5006 and follow her at Twitter.com/katienelson210.