It's important to keep in mind that religion explained a lot of stuff, especially regarding health and wellbeing (you're sick = evil spirits), before we managed to figure out the actual workings of some natural laws. I mean, hygiene was only "invented" in the late 1800s and the mere idea of washing your hands before coming in contact with a hospital patient was considered preposterous.
Nowadays, although we have amazing instruments that help us keep track of stellar bodies, we still can't quite correctly predict the weather past 1 week. Might as well say that's up to the gods.
More on topic, back on those times, each city had its patron god and it was common for conquered cities to lose their god, having the statue moved to the conqueror's temple.
I recently realized why some things like salt and garlic are so prominent in folklore for dealing with evil spirits, demons, vampires, etc.
It's probably because at some point people noticed that salt preserves foods. And since they didn't understand why foods rotted, evil spirits were blamed and thus salt must have properties that wards off evil spirits. Garlic also has anti-microbial properties (though I can only guess as to why it's specifically associated with vampires, though hanging garlic is also considered a general "ward" against evil spirits iirc).
Holy water could have gotten its reputation because people believed priest blessings had meaning, but it could also be that the rituals involved in "blessing" water actually reduced the harmful microbes. I was only able to find modern guides for making it (though I didn't look very hard and skimmed over what I did find), but I saw things like using salt, finding a clean source of water, and filtering it in this guides.
It's fascinating to me, going from what looks like random associations to understanding how those associations might have come about in the first place. Sucks that we're still dealing with a lot of the fallout of all that, though.