When Santa Rosa police officers jailed a man in early August for allegedly abusing his girlfriend, they worried the violence might escalate and obtained an emergency order barring him from contacting the woman.

But the man, Nery Israel Estrada Margos, faced a larger impediment to seeing his girlfriend. Federal immigration agents wanted to take custody of him and deport him to his native Guatemala.

Nevertheless, Estrada Margos was released the day after his arrest when he posted bail. He soon returned to the apartment he shared with his girlfriend of nine months, Veronica Cabrera Ramirez. And on Aug. 18, authorities said, he walked into the lobby of the Santa Rosa Police Department and confessed he had killed her.

With Estrada Margos, 38, now accused of murder, Sonoma County sheriff’s officials say they did in fact notify immigration authorities of his impending release — but U.S. Immigration and Customs Enforcement, known as ICE, says the heads-up came too late.

The tangled circumstances behind the release have infuriated the victim’s family and raise new questions about how local jails across California cooperate with immigration agents.

More than two years after a man who was released from jail in San Francisco despite being wanted for deportation killed Kate Steinle on San Francisco’s Pier 14, the issue remains politically and emotionally charged. It is the subject of shifting local policies, legislative efforts in Sacramento and threats from the Trump administration against local governments that have sanctuary policies.

Some advocates for immigrants believe counties shouldn’t cooperate at all with the ICE, in order to build trust with immigrant communities. But Cabrera Ramirez’s ex-husband said he doesn’t understand why a potentially dangerous man would be released when another option existed.

“If the county kept this guy in jail, my ex-wife wouldn’t have died. This could be avoided,” said Gerardo Lopez, 50, of Rohnert Park, who has two daughters ages 16 and 17 with Cabrera Ramirez, who was 42 and worked in a nursing home. “This guy shouldn’t be out on the streets and put other people’s lives in danger. I don’t get why they would leave this guy out on the streets.”

When they learned of the first arrest on Aug. 2, federal officials asked the Sonoma County Sheriff’s Office to hold Estrada Margos, who had been deported once before in 2008, in jail for up to 48 hours after his release, giving ICE agents time to pick him up.

But Sonoma, like every other county in the Bay Area, prohibits such detainers unless ICE presents a warrant, citing federal case law that says holding inmates beyond their release dates violates their constitutional rights. Advocates for immigrants argue that detainers could ensnare U.S. citizens, increase local costs and open up legal liability.

Instead, many counties now respond to detainer requests by notifying ICE prior to releasing an inmate. Some counties make notifications in all cases, and some only in cases involving a defendant who faces serious charges or has a significant rap sheet.

The precise details of what happened Aug. 3 are disputed. The sheriff’s office said it learned at 7:03 p.m. that Estrada Margos, who had been jailed on suspicion of felony domestic violence, was posting $30,000 bail. That started a 14-step process to release him, the sheriff’s office said, which included warning his girlfriend. At 8:20 p.m., the office notified ICE.

Misti Harris, a spokeswoman for the sheriff’s office, said Estrada Margos was then released at 9:05 p.m. But ICE officials say he was released at 8:36 p.m. In any event, ICE officers would need between two and three hours to pick up an inmate in Sonoma County, officials said.

Within days of his release, Estrada Margos moved back in with Cabrera Ramirez, even though police had secured a five-day protective order.

Just before 7 a.m. on Aug. 18, Santa Rosa police said, Estrada Margos entered the lobby of their headquarters and “stated that he had assaulted his girlfriend, and thought that she might be dead.” Responding to the apartment, officers found Cabrera Ramirez’s body.

Lopez said Estrada Margos had increasingly controlled everything in his ex-wife’s life, including her Facebook page and cell phone, and had banned Lopez from even setting foot in her home.

In mid-August, Lopez’s brother called to tell him Estrada Margos had made bail. Lopez sped over to the apartment to take his daughters and their belongings. Afterward, he called police twice, he said, asking them to check on her. They reported back that she was safe.

“He was a psycho,” Lopez said. “She was in fear. This guy showed up in the picture and screwed everything up.”

James Schwab, an ICE spokesman, said in a statement that Sonoma County’s policy of “notifying ICE only minutes before releasing a criminal alien clearly failed in this case as it has in too many others.” He said the “vast majority” of notifications over the last six months from the county had been too late.

“This case underscores yet again why immigration detainers are such a crucial enforcement tool and why it is highly problematic, and even tragic, when jurisdictions choose not to comply,” Schwab said.

Harris said the sheriff’s office could not have held Estrada Margos, because immigration agents didn’t provide a warrant. It is ICE’s “responsibility to pursue people who have those immigration violations. We don’t enforce immigration laws,” she said.

“People are released from jail all the time — they don’t always go out and do something as heinous as this,” Harris said. “This is awful, but it is unusual.”

Coincidentally, on the same day Cabrera Ramirez was killed, the sheriff’s office instituted a new policy that had long been in the works, one that further limits cooperation with immigration agents. Now, officers can’t notify ICE about an impending release unless an inmate has past convictions that meet a threshold of severity. Estrada Margos would not have qualified under the new rules.

In the backdrop of the Sonoma County dispute is the fight over a proposed law, SB54, authored by state Senate President Pro Tem Kevin de León, D-Los Angeles. Known as the California Sanctuary State Bill, it would restrict the scenarios in which counties could notify ICE about an inmate.

Meanwhile, the Trump administration, which has long used San Francisco’s Pier 14 case to argue jails should turn over deportable immigrants, has threatened to withhold federal funding from local jurisdictions that do not notify ICE at least two days before releasing an inmate wanted for deportation.

The specifics of the debate continue to change, but the broad contours remain. ICE officials argue that by taking custody of deportable immigrants in jails, they avoid having to track them into public places like neighborhoods and workplaces. But counties like Sonoma and San Francisco say they must balance concern for public safety with a desire not to be seen as an arm of federal immigration.

“Every day is a balance for us to make sure that we have the community’s trust and make sure we are protecting the public safety,” Harris said.

Pratheepan Gulasekaram, a professor and immigration expert at Santa Clara University School of Law, said no policy for dealing with criminal offenders guards completely against the potential for tragedy.

“Even ultra-enforcement and cooperation would still let some unauthorized persons through the cracks,” he said, “and at some point, one of those individuals might commit a horrific crime.”

As the debate continues, Cabrera Ramirez’s daughters, who found out about her death while on their high school campus, are focused only on how to carry on.

“They’re sad — they’re still sad,” Lopez said. “They’re just crying and they can’t believe their mother is gone.”

Hamed Aleaziz is a San Francisco Chronicle staff writer. Email: haleaziz@sfchronicle.com Twitter: @haleaziz