Judge says 18th-century wartime law can’t be used for deportations in first-of-its-kind ruling