Stories of "the gods" were campfire stories at some point, and were often based on the characteristics of planets and constellations. A god like osiris in egypt was associated with the constellation Orion which is visible in the winter, then "dies" in spring when the crops are growing. And in those stories, somehow the character associated with some bright lights in the night sky came to be seen as the "sun" on earth as grain.
It seems plausible that people working and living in the field of agriculture would be interested a character like Osiris, while people engaged in other activities of life would be less so, like someone who was a hunter wouldn't care that much about it, or someone who was a builder wouldn't either.
There are characters associated with each of these concerns throughout the different mythological systems, like there are numerous historical builder and blacksmithing gods like the greek Hephaestus or the egyptian Ptah. It seems plausible these different characters filled the same role a modern mascot or advertising character does today.
At some point these stories transform from folklore created and maintained by randos to copyrighted, "canonical" stories under control of the ruling class people of a given region and era. One way that might happen is via public festivals and holidays where the god mascots are in parades and public processions and that kind of thing.
Also, simply by being a popular story and a popular character the ruling class slime of any given era would see the value of these characters as a proxy for the public and controlling it. The mere concept that some aspect of a story is "correct" and canonical while any other version of a story is blasphemy or heresy or whatever is a very basic way to condition people that the dirtbags in power are in control of "all".
Another common ruling class ploy associated with claims of a canonical folklore and its god characters is that the ruling class and its priesthood serves as the intermediary to the god characters based on knowledge and expertise about rituals and sacrifices and all that bullshit. When things are going poorly for the corporate entity of the state and the fortunes of the people are down, like crop failures or plagues happen, they can blame the people for not honoring the gods correctly, or not sacrificing enough to them or whatever.
Amazingly, all this same crap goes on today in an even more strident manner than prior eras and there's a ham fisted attempt to control even comic book characters and popular entertianment on behalf of ruling class chock full of pervs and weirdos like Bill Gates.