After a star has used all of its available Hydrogen
and Helium for nuclear fusion, it collapses lacking further fuel. At this
stage it ejects its atmosphere into space. The remnant star, a so-called
white dwarf heats up to tens of thousands degrees centigrade and ionizes
the ambient gas shell.
This phenomenon appears to the astronomer as a "planetary
nebula", which has nothing to do with a planet but its appearance at first
glance similar to the fuzzy disks of Uranus and Neptune.