The origins of religious belief are an interesting anthropological and evolutionary psychology field.
Early religion (spiritual belief) did not involve any kind of morality or right and wrong.
Hunter gatherers were just looking for ways to explain good and bad luck and they invented spirits that could affect our lives, in order to explain good and bad events.
Our brains are specifically evolved around trying to figure out causality in relation to the behaviour of our peers and we naturally impute causality to agency and the model of agency that our brains are evolved to think about is the agency of other humans.
So early humans created imaginary spirits that have human qualities (anger, desire, jealousy ect.) and then imagined these spirits to reside in trees and rivers.
These spirits could be propitiated to bring about good luck (or bad luck on our enemies).
Later when civilization began to arise humans lived in larger communities and crime began to be a problem (hunter gatherer tribes do not have these problems as the communities are too small).
Only then did more organised large scale religions start to assume responsibility for moral behaviour by telling people they had to behave in certain ways in order to receive the benefits of good will from the gods.