Earlier quoted context omitted.
Legal and pushed for by the "prison industry", which has lobbyists in place to keep punishments high, tolerance low, and their low/no-wage workforce in place - whilst also getting paid by the government for housing inmates (and they send fines to government if the government doesn't meet their inmate quotas)
I was going to write that that amendment is from the Civil War, before the private prison complex could develop, lobby for, and become dependent on prison labor. But a bit of research showed that prisons were not exactly bastions of human rights in the good old days.
Netflix produced a great documentary about all of this - 13th - and it's well worth the watch.