The judge granted a preliminary injunction sought by lawyers for six transgender service members and two others wanting to enlist in the military.