Ruling is a rebuke to the Trump administration’s immigration agenda