Dharma in many places have been confused for religion. Dharma is Righteousness- Dharmo rakshati rakshitahah; Righteousness protects the one who protects righteousness. That's why more than arthasastra, kamasutra it is dharmagyana very intricate.
Purusha Shooktam gives us a hint on casteism:
Let us assume Society as a Body -bhramnosa mukha masitha= The implied meaning is Brahmins or bramhacharis (Bramho acharitha ithi Bramhachari- means one whose conducts befits Bramhan alone is Bramhacharis). People with such pure conducts are face of the society who does planning and interfacing.
- bahu rajanya kritaha= Kshatriyas who focus on body building are for defence aking to arms of human
- Vaishyas are like stomach who are resource allocators
- Padhyagum Shudro ajayatha= Who else Shudras can implement the plans and ideas well
Casteism was for team work " Saha Vavathu" and never meant for rating.
Some crooked and indisposed ppl manipulated pure things like this