Many planetary nebulae appear as rings because they form when a dying star expels its outer layers of gas and dust. This event is known as a nova, and it creates a shock wave in the surrounding material, causing it to expand in all directions.
As the expelled material travels away from the central star, it interacts with the material that the star has already expelled in the past. This interaction creates a shell-like structure, which appears as a ring or shell around the central star.
Over time, the ejected material continues to expand, and the ring gradually grows larger and fainter, until the central star is no longer visible and the ring is all that remains. This process takes thousands or millions of years, and the ring-shaped structure of many planetary nebulae is evidence of this dynamic event.