How does magnetic field store energy?

You are quite correct that a magnetic field cannot do work on charged particles, so I find that your question is a very good one. The answer is that anything that causes a magnetic field to change is liable to introduce a change in the electric field too. This is the content of Faraday's law of electromagnetic induction. In particular, when a magnetic field is first non-zero, and then is made to fall to a zero value, then it passes its energy to an electric field which in this case grows. The electric field can then pass the energy on to other things such as kinetic energy of charged particles.

There is a very nice detailed argument from the Maxwell equations and Lorentz force equation to show that it all works out correctly, as long as we associate the energy you quoted ($$B^2 / (2 \mu_0)$$ per unit volume) with the magnetic field.

My question is that if magnetic field cannot do work, then what does the energy signify?

The energy stored in the magnetic field of an inductor can do work (deliver power). The energy stored in the magnetic field of the inductor is essentially kinetic energy (the energy stored in the electric field of a capacitor is potential energy). See the circuit diagram below.

In the diagrams the voltage source is a battery. In the top diagram the switch has been in the closed position for a long time so that all transients have disappeared. Under these conditions the ideal inductor looks like a short circuit. So the voltage across the inductor is zero and the current in the inductor is

$$I_{L}=\frac{ε}{R_2}$$

The current in $$R_1$$ is zero and the energy stored in the magnetic field is

$$E_{L}=\frac{LI_{L}^2}{2}$$

In the bottom diagram the switch is opened at time $$t=0$$. The instant the switch opens the current in the inductor is the same $$I_L$$ as before the switch was opened since you can't change the current in an ideal inductor instantaneously (in zero time). So the initial current in $$R_1$$ is now that same $$I_L$$. The inductor is now delivering energy to the resistor which is dissipated as heat. The current decays in time according to

$$i(t)=I_{L}e^{-R_{1}t/L}$$

Eventually becoming zero when all the energy that was stored in the magnetic field is dissipated as heat in $$R_1$$.

Here, the magnetic field does no work. It gets converted to electric field in the wire which makes the electrons move against the resistance which in turn dissipates as heat

I said the energy stored in the magnetic field does work, not that the magnetic field itself does work. The mechanical analogue is the kinetic energy stored in a moving object can do work when bringing it to a stop. Mass is the analogue of inductance. The velocity of the mass is analogous to the current in the inductor. The inertia of mass that resists a change in its velocity is analogous to the inductor resisting a change in current.

Hope this helps

From Jackson's "Classical Electrodynamics" third edition in Chapter 5 section 16 "Energy in the Magnetic Field". He talks about how "the creation of a steady-state configuration of current involves an initial transient period during which the currents and fields are brought from zero to the final values. For such time-varying fields there are induced elecromotive forces that cause the sources of current to do work. Since the energy in the field is by definition the total work done to establish it, we must consider these contributions".

Then he goes on to derive an expression for the magnetic field energy, which is identical to yours if there is a linear relationship between $$\mathbf{B}$$ and $$\mathbf{H}$$. If you're interested you can pick up a copy, I highly recommend it if you're interested in the theoretical side of electrodynamics/physics.