Your question made me laugh a bit just because Sanaan doesn't handle the pressure well AT ALL. Sanaan, of course, has been asked to assassinate the governor! As a result, Sanaan goes a bit crazy, kind of appearing to be delirious in order to accomplish his task.
Mahfouz is trying to imply here that justice in the ancient Arab world was truly "unjust." Therefore, there are supernatural elements that must reestablish order. Here the genie is the judge, not Sanaan. The genie decides who will be punished. Sanaan al-Gamali is simply a merchant forced to kill the governor. It is clear to the reader that, due to Sanaan al-Gamali's delirium, he doesn't really know what he is doing. Unfortunately, the genie leaves Sanaan al-Gamali to be executed for killing the governor.
One scholarly theory is that the governor himself has much power, so his assassination is not something Sanaan al-Gamali is able to commit consciously. He therefore blocks it out of his mind through delirium.
Another scholarly theory is that the merchant, Sanaan al-Gamali, is corrupt himself. Therefore the "just" genie uses the merchant as a tool and leaves Sanaan al-Gamali to get his just desserts.