Small, low-density exoplanets are sculpted by strong stellar irradiation, but their primordial compositions and subsequent evolution are still unknown. Two often-considered scenarios hold that they formed with rocky interiors and H2–He atmospheres (‘gas dwarfs’) or alternatively with bulk compositions dominated by H2O phases (‘water worlds’). Here we constrain the possible range of evolutionary histories linking the birth conditions of low-density super-Earth L 98-59 d to recent observations using a coupled atmosphere–interior evolutionary model. We find that the observations can be explained by in situ photochemical production of SO2 in an H2 background, indicative of a chemically reducing mantle and substantial (>1.8 mass%) early sulfur and hydrogen content, inconsistent with both the gas-dwarf and water-world scenarios. L 98-59 d’s interior comprises a permanent magma ocean, allowing long-term retention of volatiles within its mantle over billions of years, consistent with California-Kepler Survey trends. Our analysis reveals an evolutionary pathway in which planets host volatile-rich atmospheres sustained by long-term magma-ocean degassing, shaped by secular cooling, atmospheric erosion and photochemistry. Internal and environmental processes contribute to the observed diversity of super-Earth and sub-Neptune exoplanets. Planet-evolution models explain JWST data for L 98-59 d through a new scenario: while cooling and escape shrank this planet, a permanent magma ocean supplies sulfur to its atmosphere, in which SO2 is produced by photochemistry. Exoplanets with radii between ~1.5 R⊕ and ~4.0 R⊕ are abundant and amenable to characterization using current instruments, yet they have no Solar System analogues1. This small-planet regime includes the super-Earth and sub-Neptune populations, betwee... [26720 chars]