How do devices that are rated for 120/240 volts work?
There are two common ways - both ensure that the DC/DC downconverter stage sees the same input voltage regardless of the mains voltage, which allows it to regulate more easily (smaller operating range).

The cheap/quick-n-dirty way (think low-cost PC power supply) is a range switch which controls a voltage doubler. In "low" / 120V range the AC is rectified and fed to a capacitive doubler circuit which doubles the 170V rectified input voltage to around 340V. In "high" / 240V range, the AC is rectified and is left alone (still at 340VDC or so). Bad things happen if the switch is in the wrong position vs. the input.

The modern/fancier/nicer way is to have a preregulator stage, which boosts the rectified AC voltage up to 400VDC regardless of input voltage. This is normally the function of an active power factor correction (PFC) stage, which uses AC waveshaping and some mathematics to force the converter to draw current in phase with the voltage (i.e. makes it look like a resistor with close to unity power factor) which makes for less line pollution and universal input capability at the cost of some extra losses (you now have two converters instead of one).

Of course, the DC/DC downconverter stage will have a closed-loop feedback system to ensure the output rail remains in regulation, but keeping the input voltage to the DC/DC stage within bounds affords the designer some advantages - you don't need to design the stage to handle a wide range of duty cycles which simplifies a lot of things. A DC/DC stage which accepts rectified 100-240VAC with no preregulator will need to operate over a huge range of duty cycles depending both on the mains voltage (regardless of DCM or CCM mode) and the load condition (for DCM) which affects the feedback loop and magnetic design (among other things).