In so many ancient mythologies the death deities and the afterlife is subterranean but the realm of the gods is always associated with the sky, why is that?
This is not a question for history, as the division of sky, earth, and underworld is as old and as basic as human belief development itself. It stretches back far beyond any historical source which could be cited here. A positive association with the air, upper sky, and a negative association with darkness and the underground is one of the very basic commonalities of the early human experience throughout the world. There is no one unifying proof or theory, but some assumptions can (and have) been made: the sky is the place for visible displays of power, be it the sun's warmth, the lightning's terrifying strike and sound, the howl of wind, or the motions of celestial objects in the night. It is the realm of the visible, the illuminated.
By contrast, the underground is the realm of the not visible, of the concealed. It is often the home of dangerous animals: the lairs of bears, the holes of snakes, the caves of big cats or the like. It is damp, and not many edible things grow there.
Perhaps the place to go for a thorough discussion of this is the relatively recent book by Robert Bellah, Religion in human evolution: from the Paleolithic to the Axial Age (Harvard 2011), which consults a gigantic range of comparative evidence from all over the world.
Not a historic field, but, in cognitive semantics, a branch of linguistics where semantik meaning is understood as an extension of the the human cognitive experience and construction. There, conceptual metaphors are a kind of universal metaphors that is true for all humans, as it relies on basic human experience, and the way our brains work. One such conceptual metaphor is ”up is good”, which means that in every language we have been able to study, up can always be used metaphorically as something good. If you for example say ”things are going up” or ”Im on the rise” in any language, this means that things are going good. Another such metaphor is ”down is bad” which means that expressions such as ”Im feeling down” or ”he is at the bottom” always means something negative.