The caste system has origins in Ancient India from Brahma. Brahma is the Hindu God of creation.
The caste system was legally formalized in Indian texts around 1000 BCE in a treaty called Manusmriti. According to the treaty, Indian social society was divided into four categories, with the rich at the top and poor at the bottom.
Over time, those four categories became the modern castes we see today.