Was Socrates sacrificing himself to save others or to create a legacy?
And why did he say the opinion of the unjust doesn't matter to Plato yet he yields his opportunity to escape because of what others will think?
In a sense, the answer is "both". His legacy was to "save" others albeit not in a physical sense ( we all die ). The principles that he believed in were more important than extending his life by a few years in exile.
it was a matter of principles. Escaping would not only harm others but it would also be like betraying himself.
Socrates remained true and faithful to his teachings , if it is the will of the state that he die then as a law-abiding citizen he would be a good and responsible citizen by being obedient to those laws and not seek to thwart those laws even it meant his death .