A federal judge ruled last week that requiring employers to cover PrEP, a medication that helps people at high risk for H.I.V. avoid infection, violates religious liberty because these employers perceive the drug to encourage gay and extramarital sex by making it safer. The ruling suggested extreme skepticism ‌toward‌ the benefits of health care regulation.

The judge’s finding that the government lacked a sufficiently compelling interest to justify requiring health plans to cover preventive health services that stop the spread of H.I.V. indicates disdain for the notion that we’re all in this together when it comes to public health. The decision is emblematic of attacks by judges on the legal foundations required for America’s privatized public health system to function.

Because the United States’ public health system depends on private corporations, the health of Americans is vulnerable to the whims of vaccine and drug manufacturers, monopolistic insurers and pharmacy and hospital systems, and employers that share the cost of insurance. Decades of health reforms have attempted to secure the public’s interest in universal access to affordable, high-quality health care while maintaining a privatized, fragmented system in the name of individual choice.

Bold new attacks on regulation by the judicial branch are threatening this delicate balance. As the legal historian Kate Redburn has persuasively argued, the libertarian wing of the conservative legal movement, by limiting government power, has ensured that private-public partnerships are the only politically viable path to secure essential goods and services. Now the religious wing of the movement is using those private-public partnerships to prioritize the moral judgments of a small but politically powerful minority of Americans over the secular civic values endorsed by democratic majorities.

Part of the deal lawmakers struck when they agreed to preserve a central role for private insurance and employee benefits in the Obamacare era is that private companies are now an integral part of our public health system. Health care isn’t just a personal good. We all benefit from living in a society where our neighbors and co-workers, our kids’ classmates and teachers and others have access to screening and preventive care. This is particularly the case for conditions that are infectious (like Covid and having H.I.V.) and those whose shared burdens grow significantly if they aren’t caught and treated early (like diabetes, cancer, heart disease and depression).

The Affordable Care Act recognizes the public benefits of private health coverage by requiring most health plans to cover certain immunizations and preventive services without imposing any out-of-pocket payments that could discourage people from getting the care they need. This is the regulation the Biden administration refers to when it says most people will still be able to get Covid vaccinations free of charge even after the pandemic response is fully delegated to the private market. We depend on highly regulated and taxpayer-subsidized private companies to secure access to vaccinations, viral testing, disease screening, smoking cessation services, contraceptives, counseling and a whole host of other things vital for the public’s health.

But the compromise at the heart of the Affordable Care Act isn’t working for the public’s health. Our dependence on private health care financing leaves us vulnerable to poor health outcomes and shocking inequities. Regulation of what private insurance plans must cover provides a crucial stopgap. But now, under the banner of individual rights — including the rights of for-profit employers, insurers, pharmacies and hospitals to exercise moral judgment condemning the use of health care services that medical and public health experts deem essential — the courts are eroding the legal foundations for privately financed public health.

The opt-outs some judges believe are constitutionally required for anyone who asserts a religious reason for not abiding by generally applicable rules or contributing to collective financing mechanisms are ever expanding. They are also increasingly rooted in animus toward people who exercise their personal autonomy in ways the religious right deems immoral, which the ruling last week underscored.

Nearly a decade ago, a similar case worked its way through the courts, resulting in a Supreme Court ruling that at least some for-profit corporations are entitled to religious exceptions to the contraception coverage mandate. Elizabeth Sepper, a constitutional law expert, warned that other demands for religious exemptions would follow, threatening to unravel health care, employment and civil rights regulations.

During the Covid-19 pandemic, the Supreme Court invalidated restrictions that failed to treat religious gatherings with special solicitude, adopting a far more expansive interpretation of what religious freedom requires than held sway in previous decades. Some lower court judges have recently applied the same reasoning to vaccination requirements, ruling that if medical exemptions are allowed, then religious exemptions are constitutionally required. The Supreme Court has, so far, declined to intervene in these disputes, but opponents of routine school vaccination requirements are thrilled by where things seem to be headed.

The federal judiciary, transformed by Trump-McConnell appointees, is restriking the balance between public and private interests that undergirds our democratic, capitalist approach to securing the common good while preserving individual choice. Some judges are also pressing their thumbs on the scale in favor of religious liberty and against other forms of individual autonomy.

Securing the public’s health requires Americans to work together toward shared goals. The right of individuals and businesses to opt out of doing their part by asserting a religious objection (the legitimacy of which is largely immune from scrutiny) undermines the entire system. Most people may intuitively understand that doing hard things together requires compromise and respect for certain spheres of individual freedom. But few would expect the lines to be where many judges are drawing them now.

Extreme shifts in longstanding legal doctrines may be designed to target stigmatized groups — people seeking elective abortions, transgender people and people who are intimate with H.I.V.-positive partners — but the effects will touch everyone. The reasoning in the PrEP ruling could be used to invalidate the Affordable Care Act’s preventive services coverage mandate in its entirety. Industry experts predict that in the absence of mandates, private employers and insurers will shift even more costs onto patients and their households.

Perhaps these assaults will ultimately backfire, bolstering support for public programs that are less dependent on private cooperation. But even if Americans develop a better system, the court rulings holding sway in the meantime will forever alter countless lives by privileging the moral judgments of the few over the essential needs of the many.

Lindsay Wiley is a professor of law and the director of the health law and policy program at the U.C.L.A. School of Law.

The Times is committed to publishing a diversity of letters to the editor. We’d like to hear what you think about this or any of our articles. Here are some tips. And here’s our email: letters@nytimes.com.

Follow The New York Times Opinion section on Facebook, Twitter (@NYTopinion) and Instagram.