Iti 83
This was said by the Lord…
“Bhikkhus, when a deva is due to pass away from a company of devas, five prognostic signs appear: his flower-garlands wither, his clothes become soiled, sweat is released from his armpits, his bodily radiance fades, and the deva takes no delight in his heavenly throne. The devas, observing the prognostic signs that this deva is due to pass away, encourage him in three things with the words: ‘Go from here, friend, to a good bourn. Having gone to a good bourn, gain that which is good to gain. Having gained that which is good to gain, become firmly established in it.’”
When this was said, a certain bhikkhu asked the Lord: “Venerable sir, what is reckoned by the devas to be a good bourn? What is reckoned by the devas to be a gain that is good to gain? What is reckoned by the devas to be firmly established?”
“It is human existence, bhikkhus, that is reckoned by the devas to be a good bourn. When a human being acquires faith in the Dhamma-and-Discipline taught by the Tathāgata, this is reckoned by the devas to be a gain that is good to gain.
SN56.109
the sentient beings who die as gods and are reborn as humans are few, while those who die as gods and are reborn in hell, or the animal realm, or the ghost realm are many.
AN4.33
Now, there are gods who are long-lived, beautiful, and very happy, lasting long in their divine palaces. When they hear this teaching by the Realized One, they’re typically filled with fear, awe, and terror. ‘Oh no! It turns out we’re impermanent, though we thought we were permanent! It turns out we don’t last, though we thought we were everlasting! It turns out we’re transient, though we thought we were eternal! It turns out that we’re impermanent, not lasting, transient, and included within identity.’
As to why good kamma is necessary…
AN5.31
Here, Bhante, there might be two disciples of the Blessed One equal in faith, virtuous behavior, and wisdom, but one is generous while the other is not. With the breakup of the body, after death, they would both be reborn in a good destination, in a heavenly world. When they have become devas, would there be any distinction or difference between them?”
“There would be, Sumanā,” the Blessed One said. “The generous one, having become a deva, would surpass the other in five ways: in celestial life span, celestial beauty, celestial happiness, celestial glory, and celestial authority. The generous one, having become a deva, would surpass the other in these five ways.”
“But, Bhante, if these two pass away from there and again become human beings, would there still be some distinction or difference between them?”
“There would be, Sumanā,” the Blessed One said. “When they again become human beings, the generous one would surpass the other in five ways: in human life span, human beauty, human happiness, human fame, and human authority. When they again become human beings, the generous one would surpass the other in these five ways.”