Where do magnets get the energy to repel?
Magnetic field in this case (a set of magnets in space, no relativity involved) is conservative, which means it has a potential -- each positional configuration of charges (or dipoles in this case) has its fixed energy which does not depend on history or momenta of charges. So, the work you put or get from displacing them is just exchanged with the potential energy of the field, which means no energy is created or destroyed, just stored.
As is said in a comment, the reasoning in the first paragraph is correct but the one in the second paragraph is wrong.
If you apply a force on something without "moving" the work is null and there is no energy exchange involved (this is not the same thing than doing that with your muscles, but that's another story :p). ( Work = integral[a to b] of F dot dx ; so Work = 0 if there is not "circulation").
Thus the magnets do not need any energy to statically counteract the force.
However, if you do move the magnets, then you need to give some energy. This energy is stored in the system because you cause a variation of magnetic flux: magnet 1 moving induce a variation of flux seen by magnet 2, and this will change the state of magnet 2, increasing its potential energy.
As others have pointed out, the question is somewhat misworded.
The correct question is probably just "Why do magnets repel?", which can be traced back to the question of why electromagnetism (EM) is a fundamental force of nature. Like gravity, it's one of the four known fundamental forces of nature.
Regarding the use of the word "energy". Energy is the same thing as work. Work = Force x distance. If there is a 10N [Newton] force acting on a ball, and you move the ball by 1m [meter], you have done 10N x 1M = 10Nn = 10J [Joule] of work (provided the force is constant). So, if you move the magnetic poles against each other, you do work (against the EM field). Then, if you attach the magnets to a spring and let go, the springs will compress. The 10J of work you invested is now stored in the springs! Then, if you remove the magnets and put a bullet on the spring, and let go, you can use the 10J of energy to launch the bullet (work is converted to kinetic energy), and so on =)
What happens when you push two magnets against each other, but then just hold them in place? Per the above definition of Work = Force x distance, you're not doing work, because distance = 0. But clearly your muscles are straining, and you're burning calories (which is just another unit of energy or work, like Joules), so what's going on? From a physics textbook point of view, no work is being done. This is similar to placing an apple on a table. The table is countering the force of gravity, like your muscles in the magnet example. The table has no muscles, because it is made of wood, and it won't collapse under the weight of the apple. In reality, the stiffness of the table/wood is provided by the electromagentic interactions of the atoms making up the table, so in the end it is the EM force counteracting the gravitational force. In the original magnet/muscle example, your arms are not made up of wood, so your body is doing biochemical/mechanical work to stiffen the cells in your arms by burning the food you ate. (The fact that this process is not perfect means that heat is a by product of this process, that's why your muscles get hot and you start sweating.)