Something a lot of people don't realize is that the Thirteenth Amendment didn't actually outlaw slavery.
"Neither slavery nor involuntary servitude, except as a punishment for crime whereof the party shall have been duly convicted, shall exist within the United States, or any place subject to their jurisdiction."
So a state or the federal government could impose slavery as a punishment for a crime, and in fact, forms of prison labor like chain gangs were essentially just such a thing, without violating the Thirteenth Amendment.