The ruling could affect thousands of migrants detained in Texas, Louisiana and other states under the court's jurisdiction.