The Romans were the first who used imprisonment as a form of punishment, rather than mere detention. The Law of Moses didn't prescribe jailing as a form of punishment. The Cities of Refuge were places of protection for those who accidentally killed someone. OT Law was based on the "tooth for tooth" principle of justice (not the "stone for brick" one). The closest form of imprisonment (when fines or debt became unpayable) was slavery. But, it had the limit of 6 years; the slave had be set free in the 7th year and also given means of survival. The goal was that the slave could pay back in service what he couldn't in cash or goods. Also, there were laws to protect the slaves against oppression. However, the Law didn't have mercy on those who violated the Law through acts of murder, rape, violence, theft, and so on. The Judge had to pronounce judgement on the basis of the Law. Debts could be forgiven; violation of the Law (the Decalogue), never.
Genesis tells of Joseph being put in Egyptian prison. However, historians agree that the Egyptians didn't use prisons as a punitive measure but only as places of detention or remand.