The case could affect thousands of immigrants in the country illegally who are seeking legal status through their U.S. citizen spouses.