Hammurabi, as the king of Babylon, derived his authority to write and enforce laws from his royal position. He did not receive this mandate from a higher deity or external power; it was inherent to his role as sovereign, enabling him to establish the Code of Hammurabi for governance and stability.