Chief Justice John Roberts Jr. led the court in ruling 5-4 that the Trump administration had failed to address important factors bearing on its decision to wind down the program and that failure violated the federal law known as the Administrative Procedure Act.