Chief Justice John Roberts Jr., for the third time in less than two months, on Thursday formed a surprising majority in a contentious case, defying the Trump administration’s anti-immigration agenda and drawing criticism from conservatives, while bolstering his contention the court is not reflexively swayed by politics.

Roberts, joined by the court’s liberal members, led the divided 5-4 ruling that said the Trump administration had not followed the law in its effort to end the Deferred Action for Childhood Arrivals immigration program. The ruling delivered a setback for Trump, but the court said it would give the administration a second chance to make its case to terminate the Obama-era program benefiting hundreds of thousands of immigrants who arrived in the U.S. as children.