Ruling is latest loss for Trump administration, which has sought access to state voter data ahead of the US midterms.