My motivation for this question is this dungeon scene in Ben Hur. It seems to me like long term imprisonment of any kind would be a very impractical punishment in any society where resources are tight - feeding the prisoners, paying the jailers, and building the prison. Compared to forced labor, that seems like a lot of waste for these societies.
Bonus question: if long term imprisonment wasn't common, where did the common media depiction of "lock them in the dungeon and throw away the key!" come from?
A lot of aristocratic potential troublemakers lived out their lives in comfortable monasteries in the Middle Ages and Procopius has Theodora imprisoning political enemies in deep dark cells for a few miserable years to break their spirit. Political banishment was also used for the aristocracy. It may also be remembered that crime was often considered a moral lapse which the criminal (especially the aristocratic) could atone for by pilgrimage, charity, and crusading. But for actual crime the extremes of corporal punishment and death were popular even into the 19th century. nor was this unreasonable. After being flogged a man could be returned to the village life where his hands were needed. (Just as in the 18th-19th century sailing navy.) As for the Ben Hur scene, the term slavery can cover many things probably usually meaning farm work for captured soldiers unless they defected. Though I've no real knowledge on this point I suspect that work in the mines and similar occupations was largely reserved for criminal who could be worked to death.