When you've developed them so much throughout their life, their personality, their story, that they take on a life of their own and you're simply the medium through which their story is told
A character can be more developped than another, but in term of pure and absolute storytelling, it can't be "better". A good character is one that plays its purpose for the story and for the author. Nothing more, nothing less.
As for the Mary sue, no it doesn't. The mary Sue is a sexist trope that only exist in relationship to an opposition created toward women with non explained abilities.
It's not real both socially and in term of storytelling. What might exist on the contrary is a badly developped character. I would say for example that Ray in Star wars is an example of that. Yamato is not. Yamato is a well written character.