Justice Clarence Thomas, writing for the majority in a 5-to-2 decision, said the law was at odds with the federal bankruptcy code.