Here is an experimentalist's answer:
The Standard Model of particle physics is not a theoretical invention, it is a laboriously built up compilation of the quantum number behavior in interactions of elementary particles. So it is an experimental fact.
It first started with SU(2) groups and one found that the symmetries fitted the baryon nomenclature for proton and neutron in nuclear physics to start with, allowing for theoretical potential models to be built up for the nuclear force.
Then came the high energy experiments in accelerators that gave a plethora of particles with well recorded quantum numbers organized by theorists in assuming SU(3)xSU(2)xU(1) symmetry for the groups describing all the symmetries of the particles and the way they interacted with each other. Again, these are data measured, describing Nature.
These group symmetries do not have separate masses for each particle. In the structure they could all have zero mass. So theories came up which proposed that there is symmetry breaking down in the low energies and if one goes to high enough energies everything is massless. Theories evolved to describe the symmetries and explain the data.
An example are Grand Unified Theories:
A GUT model basically consists of a gauge group which is a compact Lie group, a connection form for that Lie group, a Yang-Mills action for that connection given by an invariant symmetric bilinear form over its Lie algebra (which is specified by a coupling constant for each factor), a Higgs sector consisting of a number of scalar fields taking on values within real/complex representations of the Lie group and chiral Weyl fermions taking on values within a complex rep of the Lie group. The Lie group contains the Standard Model group and the Higgs fields acquire VEVs leading to a spontaneous symmetry breaking to the Standard Model. The Weyl fermions represent matter.
Recent theories that embed the Standard Model and the workings of GUT are String Theories.
So the three generations come from quantum number classifications of data and the theories explaining the observations have spontaneous symmetry breaking at low energies, and the the masses differentiate between generations by the mediation of the Higgs field.