I've read in a few places that elephant riders would carry spikes and hammers to kill their elephants if they panicked and started to trample their own lines.
On the other side of the coin their seems to be a number of major examples of elephants getting spooked and trampling their own lines.
Do we know if these elephant riders really carried a spike and hammer and if they did, why would they not use them when their elephants go rogue?
Yes, at least according to Livy this technique was used by Hasdrubal, Hannibal's brother. Hasdrubal brought reinforcements to help the invasion of Italy, but was surrounded at the battle of the Metaurus by the Romans. Livy wrote this about the elephants at the battle:
More of the elephants were slain by their own drivers than by the enemy. These used to have a carpenter's chisel and a mallet. When the beasts began to grow wild and to dash into their own men, the keeper would place the chisel between the ears, precisely at the joint which connects the neck with the head, and would drive it in with all possible force. That had been found to be the quickest means of death in a brute of such size, when they got beyond the hope of control. And the first man to introduce the practice had been Hasdrubal, a general who was often notable at other times, but pre-eminently in that battle.
As for why it didn't happen more often, there are a few possibilities. First, elephants are tough animals, and one in a panic would likely be difficult to kill with a hammer and chisel. This is assuming the mahout is even still alive. Also, Livy mentions that Hasdrubal himself introduced the technique, and he died in the battle mentioned. It may not have been widespread around the Mediterranean. Lastly, war elephants were incredibly expensive to raise and maintain. Killing them in such a fashion may end up being a huge waste if the animal could be calmed down after the battle and used later.
One last note, I'm not familiar at all if this technique was used in south Asia, where war elephants were far more common. You might get more information from someone more knowledgeable in that area.
Relevant English translation can be found here.