Luminous blue variables (LBVs) are hot, very luminous massive stars displaying large quasi-periodic variations in brightness, radius, and photospheric temperature on timescales of years to decades. The physical origin of this variability, called S Doradus cycle after its prototype, has remained elusive. We study the feedback of stellar wind mass-loss on the envelope structure in stars near the Eddington limit. We calculated a time-dependent hydrodynamic stellar evolution, applying a stellar wind mass-loss prescription with a temperature dependence inspired by the predicted systematic increase in mass-loss rates below 25 kK. We find that when the wind mass-loss rate crosses a well-defined threshold, a discontinuous change in the wind base conditions leads to a restructuring of the stellar envelope. The induced drastic radius and temperature changes, which occur on the thermal timescale of the inflated envelope, in turn impose mass-loss variations that reverse the initial changes, leading to a cycle that lacks a stationary equilibrium configuration. Our proof-of-concept model broadly reproduces the typical observational phenomenology of the S Doradus variability. We identify three key physical ingredients that are required to trigger the instability: inflated envelopes in close proximity to the Eddington limit, a temperature range where decreasing opacities do not lead to an accelerating outflow, and a mass-loss rate that increases with decreasing temperature, crossing a critical threshold value within this temperature range. Our scenario and model provide testable predictions, and open the door for a consistent theoretical treatment of the LBV phase in stellar evolution, with consequences for their further evolution as single stars or in binary systems.