US President Donald Trump has suffered a partial legal setback in his push to exclude transgender people from the military.