[Physics] How do 2 magnets spin by themselves if positioned precisely

electromagnetismmagnetic fields

A few years ago I went to a museum, where there was a board with 2 bar magnets, on a pole each so they could rotate.
If you rotated them so the lined up with the same poles (N) facing each other, they'd repel spinning until the south poles lined up, then they'd repel and spin so the north poles lined up and so. This was without any extra help, once you lined them up they would just keep spinning by their selves. How exactly is this possible that the 2 magnets kept producing kinetic energy?

Best Answer

They are not producing energy; their movement is a result of the work you've put during setting same poles to face each other. They will eventually stop, since this energy is dissipated by friction on their fixings and at some point their momentum will decrease to the point it will be not enough to push the system through energy pick when the same poles are nearby. After this, they will relax to their energy optimum, so probably into configuration when different poles are facing each other.