Switchmode power supplies don't use a classic transformer like the one in the first picture.
They convert the AC voltage using a bridge rectifier BEFORE it reaches a transformer, smooth it out using capacitors and then there's a circuit which sends pulses of DC voltage on the primary side of the transformer therefore generating a square wave, lots of pulses of electricity, usually between around 20k and 100k pulses a second. Depending on what voltage comes out on the other side, the circuit adjusts the number of pulses sent on the primary side.
In the first picture of your post, the transformer is always running at 50-60 Hz, that's why it's so much heavier and larger compared to switch mode transformers.
The switch in the back of some old power supplies simply rearranges how two capacitors are seen in the circuit of the power supply.
It boils down to Figure 10 in this application note (see page 7) :
http://www.ti.com/lit/an/snva006b/snva006b.pdf The switch simply connects the middle of those two capacitors to the bridge rectifier, changing how those two capacitors are seen in circuit. Those capacitors are usually rated for 200v or something like that - if the voltage switch is set to 115v and the actual voltage is 230v then the rectified DC voltage is 230x1.414 = ~ 320v and therefore the 200v rated capacitors blow up.