What was the role of righteousness in the law code of Hamurabi?
The law code of Hammurabi, like many of the other early Mesopotamia law codes, serves to legitimate the role of the monarch by framing monarchy as an intermediary between the divine and the human citizens of city. The prologues to the Mesopotamian law codes make clear that the authority of the king is contingent upon and legitimated by his righteousness. He serves at the pleasure of the gods and acts for them to implement justice, a task that includes fairness and protection of the weak. The king is especially responsible for care of women and orphans and for making sure that the rich and powerful do not exploit the less fortunate. Many of the law codes specify that if the king fails in these duties, he will be punished by the gods. The concept of justice is embodied in uniform codes of law, as opposed to the rule of the powerful.
On a practical level, this served to sustain the monarch's power against those aristocrats most likely to challenge it by allying the king firmly with the masses, as their protector against aristocratic power.
I believe the question refers to the Code of Hammurabi introduced by Hammurabi who ruled Babylon from 1792 to 1750 B.C.
Hammurabi was formulated incorporating and revising, and expanding older collections of Sumerian and Akkadian laws. This code had great influence on the civilization of all near eastern countries.
Hammurabi's code consisted mainly of a long list of rules to settle specific types of cases, involving matters such as false accusation, witchcraft, military service, land and business regulations, family laws, tariffs, wages, trade, loans, debts and theft. The code described the nature of punishment for different types of offences committed, which were harsh by today's standards. The code contains nearly 300 provisions.
On central principle discernible in the code is that "the strong shall not injure the weak." The code set up a social order based on the rights of the individual and backed by the authority of Babylonian gods and the state.
A complete translation of the code of Hammurabi is available at the website referred below.