Generally speaking, surnames came about due to a combination of population growth and increasing urbanization that created situations where you more and more people with the same name living in the same community who now needed to be distinguished somehow.
But as for those examples: Masha isn’t technically a peasant, she’s a descendant of a family of landed knights who’ve fallen into what used to be called “genteel poverty.” Janos Slynt is an ambitious upwardly mobile commoner putting on airs, but he’s also born and raised in a city of a half-million people where there probably are a lot of other Janoses.