I am doing some major under-the-hood work on a high fantasy epic that I wrote several years ago. One of the several things that I am tinkering with is the religion, which has gotten me thinking about the functions of religion within a social structure. These are some aspects that I've been considering.
Enforcement of standards of behavior -- slap people on the wrist and threaten punishment for bad behavior, either here and now or on a spiritual plane. It's just an extension of a parent's authority over a child, but to be honest most of us grown-ups need a slap now and then.
Encouraging group cohesion -- many of the behaviors that religion promotes and/or discourages are concerned with how people live peacefully in a group and work together. For example, the Ten Commandments: killing, lying and stealing are not good ways to get along with your neighbors. At the same time, religion often defines which groups of people (whether by their behavior or appearance) are to be excluded and how to treat them (usually badly. People like having permission to treat somebody badly.)
Encouraging personal development -- many religions also encourage followers to develop positive traits (the definition of "positive traits" being highly variable) that usually contribute to better group cohesion. Religious institutions also often provide a structure for people to pursue charitable or contemplative lifestyles if they are so inclined. In some societies, religion also offers the only context for pursuing an intellectual (scientific or other scholarly pursuits) lifestyle.
Providing a context for asking Big Questions -- why are we here, is there a higher purpose, why are people so cruel, etc. Religions try to answer the big, difficult questions of life. The answers can run the gamut from simple to highly nuanced. And this can be a source of dissension within a religion and a lot of violence.
Secular authority -- religious institutions can, of course, be one and the same as what we currently think of as secular governments. Or they can be separate. They can co-operate or fight each other. And of course people can fight over what the optimum arrangement ought to be.
There are plenty of aspects to consider in designing a religion, especially for a fantasy world. Here are some:
Monotheistic, polytheistic, or animist -- as in, one God/Goddess, many distinct gods/goddesses, or a system of object spirits/animal spirits/elements/sentient forces. Or atheist? What would a technologically primitive, atheist culture be like? Interesting question! files away for future thinking
Do the supernatural entities actually exist? How involved are they with their worshipers?
Religion and culture influence each other heavily. Is this a religion that is well settled in and intertwined with the culture, or is it something new that is challenging peoples' traditions?
Did the deities come from somewhere? Were they created? Spontaneously manifested? Where do they get their power? How do they treat each other?
I am building a polytheistic, well settled religion of multiple deities who were at one time mortal. They're intimately involved with their followers, the mundane world and its secular institutions. My particular kingdom and its culture tend toward the martial side of things, so both the culture and the religion will be quite organized, structured, and focus on discipline. The reasons for this tie directly in to their deities and how magical power works in their world.
What sort of religion are you building? What would you add to these lists of functions and aspects?