Prisons became the norm in the 17th century because rulers didn't want to seem too harsh by outright executing people for crimes. It's essentially a modern invention, and prisons weren't common in history except in places like ancient Rome, but even there they didn't actually build prisons they just used existing places, like basements of buildings and stuff like that. Same in the middle ages where they used cellars or the basement of castles.
It's interesting that for most of history the concept of holding a person in captivity for an indefinite amount of time didn't really exist, unless you count slavery but that isn't really the same as prison. Punishment for crimes was a one time thing, either a payment or a corporal punishment or just outright execution. It seems the idea was to inculcate the severity of the crime in people, hence, why those punishments (and they were punishments, there was no question of "reforming" anything) were carried out in public. And given that the more severe punishments required some pretty heavy evidence (in Roman law you had to be "caught" in the act. If all there was was suspicion the worst that could happen was you had to pay in monetary terms. Likewise in Islam you needed some solid evidence to chop people hands off or stoning them), public floggings or executions weren't common but they did happen and they were meant to serve as "examples" of the gravity of the crime.
I personally find that to be preferable. Any crime severe enough to warrant death implied the person was probably unreformable and as for the rest you got the adult version of a spanking and you were allowed to live the rest of your life in freedom.