The basic principle is the same for any inductor.
(Even just wire rather than a coil, though that only usually has any significant effect at extremely high frequencies).
When you apply power to an inductor - any type, a solenoid or relay coil as well as a transformer etc. - it takes time for the current to build up and a magnetic field is formed around the coil.
If you disconnect the supply to the inductor, the current tries to continue flowing as the magnetic field collapses.
That can cause an extremely high [reverse] voltage to be produced across the inductor, if there is no circuit path to carry it.
Edit - found an example waveform of an inductor switch off:
https://s19539.pcdn.co/wp-content/uploads/2017/04/voltage.jpg
In many cases it's a nuisance - with a relay or solenoid switched by a transistor, the voltage spike can destroy the transistor; or with a switching contact, it causes arcing and burning.
A "flywheel diode" or snubber circuit is normally used to allow the stored energy to be dissipated safely.
With a switching power supply, the stored energy can be routed to where it is needed, either from a single inductor or a second winding on an inductor, as with a transformer secondary winding.
This is the simplest circuit I can find:
https://encrypted-tbn0.gstatic.com/...xNy8UtPHLozJ1Z3Xe9i2HaryAlZ82EvTPBzDuHA2SGKTj
The IC switches pulses of power through the inductor. When the IC output switches off, the current in the inductor tries to maintain and the left hand side goes negative relative to ground, so the current passes through the diode and adds some charge to the capacitor each time.
This gives more details of the operation using a similar circuit (a different IC in the same family) and some of the maths involved: