An approaching armoured train is already a frightening sight, but an angry armoured train even more so.
Heavily armed and armoured, prudent raiders know not to mess with them. The average armoured train features at least one main weapon per offensive wagon, and optionally several secondary ones. The main weapons are large-caliber, hard-hitting cannons mounted on rotatable turrets. The secondary armament consists of additional firepower in the form of artillery, smaller-caliber, or anti-aircraft weapons.
All the weapons are completely autonomous, controlled by the train's AI. Said AI, while simplistic and even primitive compared to the higher developed vehicles, is only concerned with two things: getting its freight from A to B and killing anything that would prevent this. It wouldn't beat a tank at crossword puzzles, but is lethally efficient at the things it was designed to do.
Sometimes, vehicles are either too brave or too foolish for their own good. Derailing a train by destroying the tracks seems like the obvious way to get their precious cargo - and the derailing part does work most of the time. However, while their freight and some equipment might get shaken from the rough interruption, the desired effect - disabling the train - isn't achieved as easily as expected. The attackers are in for a nasty surprise. For exactly this scenario, trains have mechanisms that allow them to move without tracks. They can only move very slowly that way, but it's usually enough to put themselves back onto the undamaged parts of the track. If necessary, everything that tries to harm it in the meantime will have the incoming fire reciprocated tenfold.
Taking It Out
Only the most powerful cannons are capable of getting through a train's armour, but that alone is only a small part of the effort needed to kill it. To supply the train's weapons with ammunition, the individual wagons are outfitted with ammo stowages. Hitting these stowages is the only reliable way to take out a wagon. The AI core is located in the railcar, which is the most heavily armoured part of the train; thus, targeting it is not viable in most cases.