How do phone chargers have variable input voltage with constant output voltage?
Modern AC-DC power supplies do the voltage conversion in three steps. Roughly speaking, the process is as follows.
First, they rectify the AC into DC, so 100 V AC gets into about 140 V DC, and 240 V AC results in about 340 V DC. This is a first step. This is the range of voltages that the second stage of converter is dealing with. And this voltage has horrible ripples at 100-120 Hz.
The second stage is a "chopper" that modulates the high-voltage DC into high-frequency pulses, 100 kHz or something. There is a controller IC that drives a pair of powerful MOSFETs, which are loaded with primary winding of the isolation transformer. The transformer, as you duly noted, has a fixed winding ratio, so the output pulses would have the variable amplitude proportional to the input DC (which is 140 to 340V, not counting ripples from 50/60 Hz primary rectification).
However, the chopper also makes these pulses of different width, which is called PWM - Pulse-Width-Modulation. Thus the output of the transformer, when rectified by "half-way" diode rectifier and smoothened with a large output capacitor, on average can have variable amplitude: narrow pulses make lower average amplitude, and vice versa. This is the third stage of AC-DC converter.
So, while the transformer has a fixed winding ratio, the PWM still allows to change the output of rectifier in considerable range, thus accommodating the fixed transformer ratio and vast input voltage range, including voltage ripples.
The final control and voltage stabilization is done via negative feedback mechanism using linear opto-isolators. If the rectified voltage goes too high, the feedback makes the controller IC to produce narrower pulses, so the voltage goes down, and vice versa. This feedback mechanism not only takes care of the voltage, it also controls the overall power delivered into PSU load.
There are some fine details how the transformers tolerate the asymmetic waveforms, there are some fine engineering tricks behind the scenes, but basically that's it.
If you want to identify one 'component' that's responsible for the constant output voltage, then it's the 'feedback'.
The forward path which includes the flyback transformer pushes a controllable amount of power to the output. The voltage on the output is measured, and the feedback requests a smaller or larger amount of power moment by moment, to keep the voltage constant.
The forward path is designed to be able to run from any voltage in the input range, which needs a bit of care with design, but is fairly straightforward.
The way a flyback converter works is that its output voltage adjusts to whatever voltage is needed to deliver the power it's been asked to deliver. It can step up or down by a large ratio, to allow it to match the input and output voltage ratio.
The phone charger has to do several things in addition to regulating the voltage. It has to convert AC to DC, step down the voltage substantially and provide substantial isolation between input and output.
Since we're only concerned with regulation lets instead consider a DC-DC "in car" charger, that accepts DC over a typically wide voltage range possibly up to 28V, and converts it to 5V.
The charger probably uses a fast switching transistor and diode to rapidly switch between the input voltage and ground, then an LC filter to smooth out the switching and output the average voltage. The resulting transfer function is Vout=D*Vin, where D is a PWM duty cycle. For reasonable input voltages there will be a "D" value that yields 5v.
In its simplest form D is set by a controlling "error amplifier" comparing Vout with a reference voltage.
In more refined versions the PWM circuit is modified to cancel out the influence of Vin, two examples of this are "feedforward" and "current mode". In current mode the PWM pulse ends when the current in the inductor reaches a value. If the input voltage is higher the value is reached sooner but the output is relatively unaffected.
If this DC-DC design is "upgraded" to include a transformer then it gives the popular "forward" configuration which can be more compact and efficient than flyback as the transformer can use magnetic parts optimized for transformer use (ferrite), and the inductor can use parts for inductor use (iron powder).