The Trump administration has been dealt its first legal setback in its unprecedented effort to consolidate voter data traditionally held by states.