Let's take an example. I live in communist Russia and am accused of a crime I didn't commit. Assume the only options available to me are to be wrongly convicted, or lie and have my friend wrongly convicted instead. This is not an entirely realistic scenario -- in real life one has more options; perhaps in real life my friend and I could both escape to America -- but the slant does not help my defense of Socrates, so it's fine.
Some people proceed to measure the result by years spent in the gulag, and conclude that betraying my friend is clearly better, so Socrates' view is not just wrong but blatantly ridiculous.
But Socrates is commenting on morality, and morality isn't measured in prison years. Prison years are relevant, but also an incomplete metric.
If I am wrongly convicted, I have nothing to feel bad about. I am guilty of no sin and I have nothing to be ashamed of. Just as if a meteor struck and killed me. Such things can happen, but they don't detract from one's life morally. They aren't your fault, they aren't preventable, and they have little bearing on the question, "How should I live?" or "What sort of lifestyle is effective and virtuous?" Because they are unpreventable and random, one can't factor them into any decision making.
Similarly, if I lie and my friend is wrongly convicted, he has nothing to feel bad about. He remains morally pristine. He lived his life as well as he could. No better was available to him.
But if I lie, my own situation is not like that. Now I stay up at nights pondering my guilt. I have a secret shame to hide from my friends and family. I sinned, and I know it; how can I live with that? How can I face another day when I've intentionally done something I consider very bad? It's harder to face myself in this situation than if I am in the gulag through no fault of my own.
One might object that only certain people would feel guilty; others wouldn't care; don't those people, in one way bad people, seem to have the advantage here? But being that kind of person has consequences for one's entire life. It may be convenient as it seems in a limited, artificial situation, but as a lifestyle that has to work in a wide variety of situations, it fairs poorly. Who would want to associate with a man with no conscience? Who would befriend a person who, as a general policy, will betray his friends? And this man of no conscious cannot be much of a philosopher, or he would learn better. He lives an unexamined life; Socrates tells us the unexamined life is not worth living, with good reason.
Which is the better option is still open to debate, but Socrates' position can't be lightly dismissed.
We can take this analysis further by considering the TCS idea of coercion, which is the only kind of suffering. This analysis is very simple. Lying to convict your friend, while wanting not to betray your friend, is coercion. You or your friend being jailed, through no fault of your own, need not be, though it may be. The just life is better because it has the possibility of being non-coercive, whereas the unjust life does not.
As a further issue, how to live a good life is not primarily about what to do in specific, extreme situations. It's primarily about creating a way of life to handle many situations. So a better question is: suppose I fear I may be arrested by the KGB? What are my general plans for how to handle that? Am I really going to plan that whenever I am arrested, for whatever reason, I'll betray my friends and get out of it? Will that even work? My friends might be arrested too, or the KGB might not want to make deals, or might not keep them. Natan Sharansky's way of dealing with it, as described in his book Fear No evil, was a better plan than betraying one's friends, not just for his friends but also for himself.