The ruling, which comes as the midterm election nears, could make it more difficult for President Trump to seize control of the National Guard.