I have learned that punishments in the Torah often (always?) have a rehabilitative aspect to them as well as providing justice to the victim, e.g. someone who steals and can't pay back the value of what he stole becomes a slave, and through this experience it is hoped he will learn how to live properly. Or, even when a murderer is killed for his crime, this punishment is ultimately the best thing for his neshama.
My question is, is there ever a scenario where the Torah prescribes locking someone away as a punishment - not for the waiting period before the case is heard, but as the punishment itself. In the world in general, prison is not rehabilitative and there is a high rate of recidivism among the people who go there. However, what other alternative is there for people who are a danger to society, but not liable to the death penalty, e.g someone who is suspected of committing a murder but had no witnesses to the crime?