How does a boost converter allow for a gain in output voltage by just switching the positions of the inductor and switch?
Consider this simplified schematic of a boost converter: -

In the first half of the switching cycle the MOSFET is activated and the inductor is placed directly across the incoming supply \$V_{IN}\$: -

That action causes current to rise linearly in the inductor at a rate of \$\frac{V_{IN}}{L}\$ amps per second. As current increases, so does the stored energy. \$\text{Energy} = ½ L\cdot I^2\$
Then, in the second half of the switching cycle, that magnetic energy is released when the MOSFET disconnects (or deactivates): -

Released energy can only pass to the output capacitor and load. That energy makes the output voltage higher than the input voltage because, the inductor is attached to the input voltage source and, that means that the output voltage receives the input voltage AND the extra magnetic energy that was stored in the inductor during the first half of the switching cycle.
This makes the output voltage larger than the input voltage.