What you have heard is a Jati or caste system formula. I am posting excerpts from Agni Purana that will give you the explanation.
First step is to know what are the general tenets of faith and laws of conduct of the four varnas.
Said the Fire God: Pusakara narrated to Parashrama (the tenets of
faith and the laws of conduct to be observed by the different castes
of people as laid down by the different Manus, which were disclosed to
him by the god Varuna and a knowledge whereof imparts enjoyment of
good things in this world and salvation in this next. Puskara said: "I
shall presently discuss the articles of faith and the laws of conduct
which should be adapted and observed by the four castes of people in
their every day life, which were approved of, even by the god Vasudeva
and which carry the sanction and authority of the different Manus.
Cessation of all killing propensities, truthfulness, mercy, kindness
toward all created beings, serving god, Brahmins and one's own parents
and respectable relations, worship of one's ancestors, veneration
towards the King, perusal of good and pious literature, forbearance,
fortitude in suffering and theism are the virtues which should be
cultivated by members of the four castes and by men in general.
Agni Purana Chapter 151
This seems not unreasonable. The reality was that people of all varnas married people of other varnas. How do we handle those cases?
I have given below what Agni Purana says. I will not give the entire thing but give enough of it to answer the question.
Since the investiture with the holy thread, a member of the twice-born
caste is supposed to take a second spiritual birth and I shall
describe the castes which children born of parents not members of the
same caste, would respectively belong to. A child born of parents
belonging to different castes would get the caste of its mother, but
on the contrary a child born of a Sudra father by a Brahmin mother
would be candala. Similarly a child born of a Kshatriya father by a
Brahmin mother is called a Suta, while one born of a Vaisya father by
a Brahmin mother would belong to a Devala caste. Similarly a child
born of a Sudra father by a Kshatriya mother is known as a Pukkasa,
while the one born of a Vaisya father by a Kshatriya mother is known
as a Magadha. A son born of a Sudra father by a Vaisya mother is
called a Ayogava and thousands of different castes have been known to
have originated out of intermarriages between Vaisya girls and youths
belonging to the above said hybrid castes.
............................
Thousands of hybrid castes have arisen out of intermarriages between
Vaisya men and brides of other Pratiloma castes. A member of the
Dashika community should earn the livelihood by means of women or by
serving as a guard of the female apartments.....A member of the
Candala community should live outside the precincts of a town or a
village and all contact with him should be carefully avoided as being
polluting and harmful, his proper function in society being to collect
the wearing apparels of dead men brought to the cremation ground. A
man by renouncing this life (or the welfare of a Brahmin or for the
forbearance of the common weal, becomes exempted from all subsequent
re-births. The hybrid races should be looked upon as the off-springs
of the cravings of flesh of their respective parents.
Agni Purana Chapter 151
People like Puri's Shankaracharya are following the picture painted by Agni Purana. Of course these rules of who belongs to which caste don't make any sense. What is the reason for the child of a Sudra man and Brahmin woman be called a Candala? Why should a Candala be treated in such an inhuman fashion? Moreover while Vedas talk of only 4 varnas, some ancient Hindus came up with thousands of Varnas which is not there in the Vedas.
Fortunately, what Agni Purana says is not the whole story. There are passages in Hindu scripture that disagree with Agni Purana.
According to the aptitudes resulting from the dispositions of Nature
(gunas) and works (karma), the social order of fourfold division has
been created by Me. Though I am their originator, know me not to be an
agent but the spirit unchanging.
Gita 4.13
Maheshwara said, ‘..Neither birth, nor the purificatory rites, nor
learning, nor offspring, can be regarded as grounds for conferring
upon one the regenerate status. Verily, the conduct is the only ground.
All Brahmanas in this world are Brahmanas in consequence of conduct. A
Sudra, if he is established on good conduct, is regarded as possessed
of the status of a Brahmana. The status of a Brahma, O auspicious lady
[Uma], is equal wherever it exists. Even this is my opinion. He,
indeed, is a Brahmana in which the status of Brahma exists – that
condition which is bereft of attributes and which has no stain
attached to it. of human beings in four orders dependent on birth is
only for purposes of classification. The boon giving Brahma, when he
created all creatures, himself said that the distribution of human
beings in four orders dependent on birth is only for purposes of
classification.'
Mahabharata Anusasana Parva Section CXLIII
Yudhisthira said, " In human society, O mighty and highly
intelligent serpent, it is difficult to ascertain one's caste, because
of promiscuous intercourse among the four orders. This is my opinion.
Men belonging to all orders (promiscuously) begat offspring upon women
of all the orders. And of men, speech, sexual intercourse, birth and
death are common. And to this the Rishis have borne testimony by using
as the beginning of a sacrifice such expressions as -- of what caste
server may be, we celebrate the sacrifice. Therefore, those that are
wise have asserted that CHARACTER IS THE CHIEF ESSENTIAL REQUISITE.
.... WHATSOEVER NOW CONFORMS TO THE RULES OF PURE AND VIRTOUS CONDUCT,
HIM HAVE I, ERE NOW, DESIGNATED AS A BRAHMANA.'
(Mahabharata Aranya Parva Section CLXXIX)
I understand people like Puri's Shankaracharya supporting the inhuman caste system described in Agni Purana because Adi Shankaracharya had written in support of it in his commentary on Brahma Sutra. What I want to know is why these people ignore the teachings of Lord Krishna, Lord Siva, Yudhisthira and many others who have rejected such inhuman teachings?
Those who think of Varna as dependent on karma and guna consider astrological varna to be the varna of any child.
Every Hindu knows that astrologers try to fix the caste of every boy
or girl as soon as he or she is born. That is the real caste — the
individuality, and Jyotisha (astrology) recognizes that. And we can
only rise by giving it full sway again. This variety does not mean
inequality, nor any special privilege.
The Complete Works of Swami Vivekananda, Volume 4, Writings Prose, A Plan of Work for India (Written to Justice Sir Subrahmanya Iyer from Chicago, 3rd Jan., 1895.)