I think you have confused the purpose of religion with the result. I think the purpose is to harmonize a society under a common moral code to insure fidelity to that society. I think this is the result of the fact that the will to justice and fair play, equality and the decency one would like for oneself, is guaranteed to all. I believe it no accident that moral codes across time and space have great commonality in their seemingly varied laws.
The use of the law to control social classes, I would say, is a later evolution based on the ego need to maintain class privilege regardless of personal merit, the advent of psychopathology, the very thing religious law was intended to prevent.
This inalienable understanding of justice vs injustice I believe can be sensed without words, a universal language of the heart. It is for this reason that no matter how screwed up a religion becomes the ones the endure in the world will always have members who see the truth. There are millions of Christians, I believe, who absolutely abhor Donald Trump and can see in him everything we imagine about the anti-Christ, the god of the angry, sick, aggrieved ego. That's my opinion.