An inductor stores energy in form of magnetic field. In case of capacitors the energy is stored in electric field, and since electric field can do work the stored energy can be spent. Here, magnetic field does not do work, then how stored energy gets spent?
Sometimes it's a good method to see things on the particle level.
In case of capacitors the energy is stored in electric field,...
In detail, electrons are separated and accumulated on one side of a capacitor. For the separation is needed energy and connecting the two sides of the capacitor the electrons flow back to the other side. Having some device (resistance, lamp, motor) in the circuit, you’ll “see” the work from this current.
... and since electric field can do work the stored energy can be spent.
The better description is to talk about a potential difference between two points of a circuit. This potential difference is the result of a charge separation. And the charge separation in turn always has the effect of a macroscopic electric field.
Besides the electric charge, the electron is a magnetic dipole. In permanent magnets the macroscopic magnetic field is caused by the alignment of electron (and protons). This self-alignment is destroyed by higher temperatures.
In an inductor the electrons get align with their magnetic dipoles during the electron flow on their spiral path and a macroscopic magnetic field is created. But only for temperatures near zero Kelvin a self-alignment occurs, in the common case the alignment gets lost immediately after switching of the current.
Here, magnetic field does not do work, then how stored energy gets spent?
Starting a current through an inductor, a higher resistance is measurable in the circuit. Partially this resistance comes from the work, which has tobe done to align the electrons magnetic dipoles during their transition through the inductor. switching off the current, for a moment a current in the opposite direction is remarkable (Lenz’s law). this current is the work, realized from the magnetic field of the inductor. And, in detail, it occurs from the return of the aligned electric dipoles into their random directions.