From the magnetic field. The catch is that, to reload the gun, you have to do work at least equal to the final kinetic energy of the projectile. Realistically you have to account for energy losses like friction and collision inelasticity.
Same place any other distance-based potential energy (like gravity) comes from: being far away from the magnets -- and on repeated firings of a ball, from pulling it away from the magnets.