The ruling marked one of the few cases in which the justices did not divide along the court's usual 6-3 ideological lines.