The flyback diode and its applications

In your first example, before the switch opens, there is a current flowing through L. When the switch opens the current wants to continue flowing in the same direction so this has to create a positive voltage on the right-hand side of L relative to the left hand side (which is fixed at +Vs).

This positive voltage causes current to continue to flow and this current finds the path of least resistance through diode D. It continues to flow until all the magnetic energy in the inductor is gone then current = 0 and the voltage on the right hand side of L is the same as the left hand side i.e. +Vs.

In the 2nd example with the H bridge, all the diodes are needed because it has to cater for scenarios when the motor is deactivated i.e. pin 3 and pin 6 are open circuit. This is the simplest way to explain it I think. The motor current may have previously been upwards or downwards so all four diodes are needed to catch the back emf when the motor is switched off.

Also, current flow back into the H-Bridge circuit does not appear very practical.

That's how they work.