SAN FRANCISCO—A federal judge ruled late Thursday that the Trump administration violated Anthropic’s First Amendment rights by blacklisting the artificial-intelligence company as a supply-chain risk.