Many want to understand how and why religion "works", as then, they can predict religous behavior and this is all important to protect against behaviors that might endanger all of us. So, some have tried various means to understand.
One way of understanding is "belonging", where group behavior is predictable, as we are all social animals. But, group behavior can be dangerous as much as beneficial. This becomes problematic, too, when there are "free radcals" in the group that might lead the group "astray" from the "social order" to be maintained! And then, when groups become tightly identified, what happens to the "rest of society"?
Another way of understand religion is "belief". These are philosophical ways of understanding life and all that is. "God" is the beginning and end of such thinking, as it is "theological". When theology is ahistorical, people become prone to disconnect from the "real world", either through their "denial" of reality; their belief that they will change reality into some spiritualized vision; or their withdrawal from reality and the real world!
"Behavior" is really the "end" of what scientists want to understand, as behavior is "social control". Social control is needed when radical believers want to implement their vision upon society, or act in ways harmful to themselves because of such a belief. Some psychologists have believed that social conditioning is the best form of "training the human animal". But, one must understand how that must be done without co-ercive measures. That becomes problematic to a free society!
Belonging is first formed within the family of origin. A child's sense of "who he is" and where he fits in the family is an important step to furthering the child's advancement or inhibiting it.
Beliefs are also first grounded within the family of origin. These might not be formally taught as in religious communities, but are modelled by the families "way of life". These become internalized values, until the child becomes "of age" and gains his own sense or what and why he wants to own or dis-own a certain familial value.
Behaviors are the result of a person's belief system. And one's belief about themselves and the world make for how one engages the world and presents themselves.
In a free society, it becomes almost impossible to predict and control behavior at large, because individuals are free to believe differently and contingencies are numerous!