They passed through inheritance;
'House-elves come with big old manors and castles and places like that, you wouldn’t catch one in our house ...’ ~ Chamber of Secrets - pages 27-28 - Bloomsbury - chapter 3, The Burrow
The 'one house, one family' adds another layer, but I think Hogwarts is a little different when it comes to defining 'family' perhaps
One could look upon the Hogwarts Principalship as something of an inheritance. Since Hogwarts isn't owned by any one person, for it to pass to their kin, the Headmaster comes closest.
One would imagine once the elves arrived, back in the early days of Hogwarts, it was established their ownership would pass as such.