I think Socrates did it to support his own reasoning that the law should be followed. He would be a hypocrite to his own legacy, which would of lowered respect for him, and an outright denial of his principles by many.
It was his life to do with as he wished. In my view though, the State was being unjust, and was therefore not entitled to execute Socrates. In my view, he seems to have gone to his death in defense of his belief that everyone should obey the law. In my view, "an unjust law is no law at all" and I would not "allow Athens to sin against philosophy twice".