It’s not necessarily legal.
The judge hasn’t ruled yet on whether Musk broke the law. He simply declined to issue a preliminary injunction.
A preliminary injunction tells someone to stop what they are doing while the court case plays out. In order to get a preliminary injunction, you have to convince a judge that there will be irreparable harm by letting someone continue.
In other words, a judge might rule against an injunction but nevertheless end up ruling against the defendant. Especially if the judge thinks the harm has already been done.
Federal law supercedes state law. That doesn’t mean federal officials can go where they want.
IIRC, the issue is that the Voting Rights Act gave DoJ the power to observe elections, but the SCOTUS partially nuked the VRA. So now it’s not clear whether the DoJ still has that power, and the usual suspects are taking advantage of this ambiguity. Possibly hoping to give the SCOTUS a chance to nuke more of the VRA.