WASHINGTON — On July 1, 2015, a single gunshot rang out on San Francisco’s Pier 14, fatally wounding 32-year-old Kate Steinle. By July 3, then-presidential candidate Donald Trump was tweeting about it.

An undocumented immigrant and five-time deportee who had been released from San Francisco Jail was charged with her murder, though he was acquitted two years later. By the time he went on trial, the incident had become a rallying cry for conservatives in general and Trump in particular. He took action just days into his presidency to block federal funds to sanctuary cities, a catchall term that describes jurisdictions that limit cooperation with federal immigration enforcement.

And then Trump’s administration began to lose — repeatedly — in court.

Now, experts say that by continuing to press the issue, the administration’s strategy could backfire — possibly jeopardizing the cooperation that federal authorities now receive from many local governments and preventing Congress from even passing legislation on the topic.

Trump’s first legal setback came in response to the executive order he issued to block any federal funding to sanctuary cities, when a federal judge in San Francisco ruled in April 2017 that he could not broadly withhold money to force cooperation with immigration agents.

Trump, via then-Attorney General Jeff Sessions, then tried to impose more targeted punishment, making law-enforcement grant money conditional on cities’ cooperation with immigration enforcement. Courts in Chicago, Philadelphia, Los Angeles and San Francisco again blocked his efforts. The Justice Department also sued California to try to preempt its state sanctuary law. A federal judge in Sacramento blocked that as well.

But it’s not just the grants that are at stake — the administration is at risk of losing the one law on which it has hung all its efforts.

The key development came in May in an unrelated case, when the Supreme Court ruled that a federal law prohibiting states from legalizing sports gambling was unconstitutional. The justices said the law illegally “commandeers” states to follow federal policy and intrudes on their lawmaking authority.

The decision had major ramifications for sanctuary cities litigation.

The Trump administration’s antisanctuary campaign is based on a piece of immigration law commonly referred to by its code number, 1373. That law prohibits state and local governments from restricting information about an immigrant’s status from federal officials.

Former President Barack Obama’s administration made some law enforcement grant money conditional on compliance with 1373. The Trump administration seized on that and sought to expand the interpretation of what was required of cities and states.

The law, government lawyers argued, covered more than just a person’s immigration status. They said it also required local governments to share the date immigrants would be released from custody, so federal agents could pick them up. The law became the underpinning of the government’s lawsuit over California’s sanctuary legislation.

However, lower courts following the Supreme Court’s ruling in the gambling case have applied it to 1373-related lawsuits — and have found that the immigration law also violates local governments’ rights.

A federal judge in Philadelphia ruled in June that not only were the immigration-related conditions on grants unconstitutional, so was 1373 itself. A federal judge in Chicago followed suit in July. In October, U.S. District Judge William Orrick in San Francisco agreed, ruling in favor of San Francisco and striking down 1373. On Friday, a judge in New York did the same, saying a previous appellate court decision in the region also would have to fall after the Supreme Court’s ruling.

If the administration leaves those cases where they are, the effects will be relatively minimal. Each of those lower court rulings applies only to the cities that sued the Trump administration — they would not become nationally binding precedent unless federal lawyers appeal the decisions to higher courts and lose.

“If I were them, I would not want this at the Supreme Court, and would just leave it, leave these decisions as they are and just let the rest of the country continue to think that 1373 is constitutional,” said Bill Hing, professor of law and migration studies at the University of San Francisco.

Some issues in the cases have been heard on appeal, but those were decided before the Supreme Court’s gambling ruling. The Justice Department has filed a pending appeal in the Chicago case, looking not to overturn the judge’s decision but to seek a ruling that it and the administration’s other courtroom defeats should apply only to the individual cities and not nationwide.

Josh Blackman, a professor at the South Texas College of Law Houston and contributor to the conservative legal group the Federalist Society, argues that winning on the issue of limiting nationwide rulings would be worth it, even if the administration jeopardizes 1373 in the process. He argues that appellate courts can decide these cases without needing to weigh in on 1373, which he called a “useless statute.”

“If that statute’s declared unconstitutional, then so what?” Blackman said. “The government often enacts policies that they know have a greater than average chance of failing, but if it advances the agenda of the executive branch, it’s worth taking the chance.”

Hing, though, called that strategy risky in light of the high court’s gambling decision. If the Trump administration keeps losing, he said, cities that cooperate now with federal immigration authorities could be sued by sanctuary advocates with legal precedent on their side.

Justice Department spokesman Steven Stafford said it was “absurd” to argue that sanctuary jurisdictions should receive federal law enforcement funding. The agency, he says, wants local authorities to “stop actively obstructing federal law enforcement.”

That position “is not only allowed by the Constitution, it is demanded by the Constitution,” Stafford said. “The Supreme Court’s decision in (the gambling case) has no bearing on the federal government’s ability to place conditions on funding.”

Immigration attorney Leon Fresco, who served in the Justice Department under Obama, said the Trump administration may have never believed it would prevail on sanctuary cities, but pursued the case to win a political talking point and potentially spur congressional action. But he warned that if courts make clear it’s unconstitutional for the federal government to force state and local governments to cooperate with immigration agents, it could give congressional Democrats cover for not acting.

“They’re making it easier for Democrats to say, ‘It’s not I’m not for solving this issue, it’s that we legally can’t,’ ” Fresco said. “The more (Trump officials) tease this out and make it true, the more likely they are to lose not just the legal issue, but the political issue.”

Tal Kopan is The San Francisco Chronicle’s Washington correspondent. Email: tal.kopan@sfchronicle.com Twitter: @talkopan