Right, religions have existed before and during class society. But religions under class society get used to perpetuate class rule. Example: Christianity gets appropriated by the empire, the church becomes all powerful, Christianity becomes another instrument of repression in Europe. So really you can only purge the reactionary elements with socialist revolution.
And I don't think explicitly egalitarian religions are possible under class society. Isn't Sikhism supposed to be that, yet it fails in several regards?