For individuals and for societies, religion often involves a huge investment of time and resources. To mention just a few examples, Mormons are expected to contribute 10% of their income to their church. It's estimated that traditional Hopi Indians devote an average of one out of three days to religious ceremonies, and that one-quarter of the population of traditional Tibet consisted of monks. The fraction of resources in medieval Christian Europe devoted to building and staffing churches and cathedrals, supporting the many orders of monasteries and nunneries, and underwriting crusades must have been large. To borrow a phrase from economists, religion thus incurs "opportunity costs": those investments of time and resources in religion that could have been devoted instead to obviously profitable activities, such as planting more crops, building dams, and feeding larger armies of conquest. If religion didn't bring some big real benefits to offset those opportunity costs, any atheistic society that by chance arose would be likely to outcompete religious societies and take over the world. So why hasn't the world become atheistic, and what are those benefits that religion evidently brings? What are the "functions" of religion?
Essentially, the same argument shows that the common cold must be beneficial, or else those immune to it must have taken over the world. That argument does not prove that the cold virus is beneficial to humans. So, merely noting that something is common doesn't show it is beneficial to humans. Bedbugs are common and they have clear costs - but that doesn't mean that they must have associated benefits that outweigh these costs. The whole argument is just a fallacy.