The ruling affirmed a lower court decision that deemed a program protecting about 600,000 young immigrants from deportation to be illegal but allowed current recipients to renew their status.