The ruling from the New York-based Second Circuit Court of Appeals is the first in the nation to reject the Trump administration’s position that nearly all undocumented immigrants must be detained.