WASHINGTON—A federal judge in Texas on Friday ruled that the Affordable Care Act is unconstitutional now that Congress has eliminated a penalty for those who forgo health insurance, casting doubt on the embattled health law and coverage for millions of Americans.

U.S. District Judge Reed O’Connor, an appointee of President George W. Bush, ruled that the entire Obama-era health law is invalid, siding with the claims of 20 Republican states that brought a lawsuit seeking to strike down the ACA.

Republicans...