Work done by magnetic field on current carrying conductor

The work comes from the battery that is driving the current through the wire.

Even if the wire were stationary, the battery would be supplying work at a rate $I^{2}R$. But with the wire moving, the battery would need to be supplying extra work at a rate $\mathscr{E}I$ in order to overcome the emf generated by the moving wire.

Now, $\mathscr{E}$ is equal to the rate at which the wire cuts magnetic flux so $\mathscr{E}=BLv$ (in which $v=\frac{d}{t}$), so the extra rate of doing work has to be $\mathscr{E} I=BLvI=BLdI / t $. And this is equal to the rate of mechanical work done on the wire!


But magnetic force cannot do any work on a moving charged particle and hence total work done on all particles by magnetic force should be zero. Where does the work IBLd come from?

Sum of works of magnetic forces on each charged point particle in the wire (assuming it is made of point particles) is indeed zero (this follows from the fact that magnetic force on point particle is always perpendicular to particle's velocity).

However, the macroscopic work $IBLd$ is not that sum; instead, it is work of a macroscopic force, acting on the whole wire. This macroscopic force is due to existence of current $I$ inside the wire, but it does not act on that current, it acts on the wire itself.

This macroscopic force is properly called Laplace force, or ponderomotive force. It is also common to call it simply magnetic force, due to its origin - it appears due to presence of magnetic forces acting on the charge carriers. Unfortunately, it is also quite common to call it Lorentz force, but that is grossly incorrect. Lorentz force should refer only to force acting on a microscopic body such as the charge carrier.

The Laplace force acts on the body as a whole and it is not given by the Lorentz formula and it is not perpendicular to velocity of the body; hence it can, and often does work (electric motors).

It arises due to fact that charge carriers are confined to the wire, even while the Lorentz forces act on them; if there was no confinement, the Lorentz forces would make them curve their trajectory so as to escape from the wire on one side. This does not happen, as even slightest deviation of distribution of current inside the wire results in restoring force due to rest of the wire that keeps the charge carriers confined. By Newton's 3rd law, the charge carriers exert opposite force on the rest of the wire too - and sum of those is the Laplace force. Thus the Laplace force is internal force, acting from the charge carriers on the rest of the wire.

The work done by this force is thus work of internal forces in the wire, not work of the external magnetic field. The energy is funneled from the voltage source, through the EM field of the voltage source and the circuit, to the mechanical energy of the wire.