When did scientists discover that the Sun has a life cycle and that it is going to die?
Although various astronomers have speculated that the Sun was a star (some were imprisoned or even burnt alive for such heresy), this was not known definitively until 1838 when Friedrich Bessel used parallax to calculated the distance to 61 Cygni.
In the late 19th century, Lord Kelvin provided rather small (less than 100 million years) for the ages of the Sun and of the Earth. He did not know about fusion. The nature of what powers the Sun was not known until the 1920s based on observations of the mass of a proton versus that of a helium-4 nucleus. The exact mechanism wasn't known until 1938 when Hans Bethe developed models by which hydrogen fuses to form helium.
This model provided the basis for knowing that the Sun will eventually die as it will eventually run out of fuel. Working from this, a number of scientists developed models of what happens inside stars of various masses based on the growing knowledge of stellar nucleosynthesis.