The ruling was a major lift to the G.O.P. efforts to build a structural advantage through redistricting.