The ruling is the latest twist in an intense legal drama that has plunged the state into electoral chaos.