The 6-3 ruling marked the second time this year that the court has invalidated a major Donald Trump initiative.