It is more appropriate to call this an electromagnetic train, rather than electric train. How does it work?
The “train” moves because of the force that acts on it, in this case, electromagnetic force. Note that, for the electromagnetic train to work, the permanent magnets (attached to the two ends of the battery) and the copper wire that makes up the coil have to be in direct contact, i.e., without insulating coatings.
When the battery and attached bar magnets are placed in the coil and direct contacts are made, a closed loop is formed and current starts to flow. When current flows through a solinoid, magnetic field is produced (as in an electromagnet). The magnetic field generates force on the permanent magnets attached to the battery, producing the force that pushes the “train” forward.
Note: Since the permanent magnets are conducting, the various contacts points are effectively at equal potential. The current flow starts from and ends at the points indicated in the above figure.
When current flows in the direction shown in the right figure, following right-hand-rule, the magnetic field produced is pointing to the left. For the permanent magnet on the left, it is pushed to the left (north pole and north pole repel each other). On the other hand, the permanent magnet on the right is attracted towards the left (south pole of the electromagnet attracts the north pole of the permanent magnet). Together, they push the battery to the left. As the battery moves, the contact points also moves, and the condition keeps repeating itself, thus the battery continues to move.
Note: It is crucial that the two permanent magnets are attached to the battery in opposite directions, otherwise the experiment won’t work.