It's a good question. One could argue that the ancient world was cruel, but that's not true everywhere. The barbarian law codes focused on restitution or penalties, but corporal punishment was rare. In tribal societies the worst punishment is expulsion, that is, being ostracized. That penalty turned you into a non human whom anyone could kill or enslave without fear of any kind of retribution from kin.
The Mosaic code is very harsh; maybe the Semitic way was harsh (and by Semite I include Syrians, Assyrians, Arabs and others in the area).
The early cities already had a diverse population of merchants, traders, and others who were not native speakers and who had foreign ways. Maybe it was felt the harsh punishments were necessary to prevent things from becoming chaotic.
The other thing to consider is that before the modern era there was no prison system. Sentencing malefactors in general to prison terms instead of maiming them or killing them came out of the reform movements of the 1830s and 40s.