Law doesn't seek to punish but to rehabilitate. Act of taking freedom away from the criminal is violent enough. Treating them badly is just a sign of unfair/poor society that cannot maintain (afford to keep) it's promise to be civil to all citizens.
Rehabilitate and/or deter. The extent to which it is either the former or the latter depends on the country. That also determines whether or not "treating them badly" should be a feature of the justice system.