The ruling is a blow to President Joe Biden, who has called for tighter restrictions on firearms, including an assault weapons ban.