"The only time it was legal was under the British Rule."

How is that at all relevant?

Hindus had been practicing the caste system for hundreds of years before the British even arrived.  They were doing it when the Timurid Dynasty invaded from Asia, practiced it through the entire length of the Mughul Empire, and were still practicing it when the Raj was founded in the 18th century.  All the British did was codify what was already there. The Muslims of the Mughul Empire prior didn't like the caste system, and argued against it near constantly, which just made the Hindus more stringent in their application, for the most part. The fact it wasn't popular certainly didn't stop it from happening.

Google the Islamic books "Akbranama', by Abu al-Fazal ibn Mubarak. It's a three volume history of Akbar's reign, but Fazl partly wrote that book for his fellow Muslims, hoping to put the Hindu caste system into words and concepts his fellow Muslims would understand and tolerate.