While it may seem that quantum numbers were invented out of the blue, that isn’t the case. They derive directly from solving the Schrödinger equation:
$$\hat{H}\Psi = E \Psi$$
One of the simplest Schrödinger equations is that for a particle in a box — the one most quantum chemistry or quantum mechanics courses start with and therefore found in every textbook for quantum chemistry which is why I won’t repeat it here. But in a nutshell: You need a function that you can differentiate twice and which will then reproduce itself with a constant factor E. That can be achieved by sine waves. You cannot say a priori which frequency the sine function will have, though: If the box has size l, it works for sine waves with the wavelengths $2l,\ l,\ \frac{2l}{3},\ \frac{l}{2},\ \dots$ and the corresponding wavenumbers $\frac{1}{2l},\ \frac{1}{l},\ \frac{3}{2l},\ \frac{2}{l},\ \dots$ or $\frac{n}{2l}$ with n being a natural number. n is therefore the simplest case of a quatum number.
If you solve this equation for an electron orbiting a proton, the solutions are much more complicated (and there are intermediate steps often presented in the quantum chemistry courses to make the transition easier). However, n still turns up as a variable, corresponding to quanted amounts of energy. For certain values of n, there are additional variables whose values cannot be derived a priori but which can only assume specific values — they correspond to the other quantum numbers.
This in itself is just a solution to a mathematical equation. The real beauty lies in the fact that these quantum numbers can be used to explain experimental observations such as hydrogen’s flame colours. All quantum numbers can be used to explain some property one has deduced by experiments.
So tl;dr: It’s just what maths tells us will be the case.