A federal judge on Friday tossed the state of Maryland’s lawsuit alleging that President Trump is damaging the 2010 health care law and may sow chaos by refusing to enforce it, as a major case against Obamacare wends through the courts.

U.S. District Judge Ellen Lipton Hollander said Mr. Trump may loathe Obamacare but the state’s request for an order declaring the Affordable Care Act constitutional — to head off future “sabotage” — was speculative, so Maryland didn’t have standing to sue.

“Neither the president’s zealous attempts to repeal the statute, nor his derisive comments about it, support an inference that he will fail to enforce the law,” she wrote.

“In effect, the state proclaims that the sky is falling,” Judge Hollander added. “But, falling acorns, even several of them, do not amount to a falling sky.”

Maryland Attorney General Brian Frosh, a Democrat, said he sued because his state’s finances would suffer if the administration fails to uphold former President Barack Obama’s law. More people would become uninsured and seek uncompensated care in their hospitals, and their investment in a state-run insurance exchange would be squandered, he charged.

Mr. Frosh pointed to Mr. Trump’s actions to undermine the law — from statements against the program to more concrete steps such as canceling cost-sharing payments to insurers, slashing Obamacare marketing and offering bare-bones alternatives to plans in the law’s exchanges.

The administration also refused to defend the law against a state-driven lawsuit that says Congress’ decision to gut Obamacare’s “individual mandate” for shirking insurance rendered the rest of the program unconstitutional.

A federal judge in Texas ruled in favor of the GOP-led states in mid-December, finding Obamacare was no longer constitutional, though he stayed the ruling pending an appeal.

Judge Hollander said the administration’s own comments to the Texas judge undermined Mr. Frosh’s position.

For instance, Justice Department attorneys asked U.S. District Judge Reed O’Connor, presiding in Fort Worth, not to interfere with the 2019 open-enrollment period, fearing disarray.

“The Trump Administration’s decision not to defend parts of the ACA in court is not the same as failing to enforce it,” Judge Hollander wrote.

Mr. Frosh said Friday’s ruling simply means he has to wait and see if Mr. Trump fails to uphold the law.

“We will resume this litigation immediately if the president breaks his promise of continued enforcement or when the stay of the Texas court’s decision is lifted,” he said.

In the meantime, he said he will work with the Maryland legislature to protect residents who rely on Obamacare’s benefits and consumer protections.