I think you are looking at religion from "modern Christian" perspective. That is basically where Christianity has been pared down to bone and the only functions it serves are Church or Holiday related. A look at a more diverse cross-section would give a better idea about the function of religion within society.
For example, it provides tradition and structure to a person's daily life - like fasting on certain days or having a ritual every morning. A lot of people need that sort of structure in life - I have no idea why they'd need it, but apparently, they do.
It also lays out the infrastructure for a lot of momentous occasions in life. Like birth or marriage or death - there is already a system in place with what to do and how to do it with no reason to try and figure it out all by yourself.
As for the community function - it includes more than just Church congregation. There are festivals and events that require active participation and are open to all - not just those you'd rather associate with. There maybe other alternatives that are more beneficial, but it'd be tougher to get people to participate without any obligation over them.
Finally, in most societies, religion is so closely tied with the cultural heritage that it'd be nearly impossible to separate one from the other.
For example, it provides tradition and structure to a person's daily life - like fasting on certain days or having a ritual every morning. A lot of people need that sort of structure in life - I have no idea why they'd need it, but apparently, they do.
It also lays out the infrastructure for a lot of momentous occasions in life. Like birth or marriage or death - there is already a system in place with what to do and how to do it with no reason to try and figure it out all by yourself.
As for the community function - it includes more than just Church congregation. There are festivals and events that require active participation and are open to all - not just those you'd rather associate with. There maybe other alternatives that are more beneficial, but it'd be tougher to get people to participate without any obligation over them.
Finally, in most societies, religion is so closely tied with the cultural heritage that it'd be nearly impossible to separate one from the other.