Socrates made the right choice in drinking the hemlock. According to The Enchiridion, one must do what is right even if others judge that decision. Socrates followed this belief and obeyed his sentence even though his friends wanted him to escape.
The Enchirdion also says "Some things are in our control and others are not. Things not in our control are body, property, reputation"" (1). Meaning it wouldn't matter what he did, his reputation and whether or not he is found guilty according to others is out of his control. To kill himself over his reputation is pointless.
Socrates himself said in The Phaedo that the body is nothing but a distraction from acquiring knowledge. Death would not have been much of a consequence for him. Instead it would have benefited him. He believed that once he was dead he could focus on his mind and soul, which is all a philosopher like Socrates would want.
According "The Philosopher's Mean", part of being a philosopher is blending in with the common man, "perverted forms of self display, are to be avoided". By choosing to kill himself, Socrates is creating a relatively big ordeal and a big trial and drawing negative attention to himself and philosophy in general. Also, it is plainly stated in the Philosopher's Mean that penance is not a part of philosophy at all.
Socrates also has a duty as a philosopher to spread his teachings and pass the knowledge of philosophy on. Committing suicide would be a transgression of his duty which according to David Hume's "On Suicide" is a reason that committing suicide is not okay.
Socrates is well known for saying that he only knows what he doesn't know. He had no idea what awaited him outside of Athens. It would have been a huge risk for him to escape because he didn't know what would happen to him. Maybe he would have lived peacefully for the rest of his life, but there was just as much of a chance that he would've met the same fate there as in Athens.
As said in the previous argument, Socrates is know for the saying, "I only know what I don't know". What awaits us after death is perhaps the biggest unknown. That is a bigger risk than escaping to Athens and continuing on his life rather than cut it short. Again said in a previous argument, he believed that death allowed for humans to focus solely on the mind and soul. He can't know that or not know that, no one can retell their experiences while they are dead.