Answer:
To maintain the stability in his empire.
Step-by-step explanation:
The codex of Hammurabi was notorious for giving harsh punishment for criminals who violated the laws. (One small example, if you're caught stealing in his reign, your arms would be cut off)
I think , he imposed these laws and harsh punishment to maintain the safety and stability of his empire.
If criminal behaviors were left unpunished, the other citizens wouldn't feel safe to do productive activities such as farming, learning, or even walk at night. They would live in constant fear that someone will just come into their house and steal everything that they've worked hard for.
Imposing harsh punishments will massively discouraged the criminals. As a result, the citizens could focus all of their energy on productive things.