Note that the diode is reverse-biased in that inductor example. What happens when the power is cut is that the inductor's collapsing magnetic field creates "counter-EMF"; a voltage. This voltage is opposite to the voltage which had been applied, and forward-biases the diode. The diode at that point conducts, allowing the energy to be dissipated. Without the diode, the energy will still be dissipated, but elsewhere. It can create an electric arc that can damage other components or start a fire.
The MOSFET semiconductor doesn't generate counter EMF, but is a sensitive device. A diode can protect it from a discharge coming into the semiconductor from the outside by acting as a short around the MOSFET. In there is only one diode. The assumption is that the external discharge will be in opposite polarity to the power supply rails; i.e. the threat that is being recognized by this defense is that of the flyback voltage from a power supply that contains inductive components. A single diode like this won't adequately guard the MOSFET against static discharge.
The "advantage" of a diode compared to a resistor is that its resistance depends on the magnitude and polarity of the voltage which is applied, whereas an (ideal) resistor has a constant resistance. This is also an advantage of the resistor with respect to a diode.
We can't replace the diodes with resistors in these uses, because we need the resistance to be very small, and such a small resistance would unconditionally behave as a short circuit.
A diode (to a first approximation) acts as a short only when there is a forward-biasing voltage on it (or it has been driven into reverse breakdown). Between these extremes, it is an open circuit. So it's like a voltage-dependent switch.