Execution by elephant has been described as far back as third century BC. There were typically two ways this was done. The first involved a specially trained elephant executioner who was sent in to trample those sentenced to death. The descriptions can be disturbing so don't read if you think you'll find it too extreme.
An example was written by Louis Rousselet. Rousselet describes a locksmith who was condemned to death for helping prisoners escape. The method of execution involved tying the man to the elephant’s hind leg and having the elephant rapidly trot through the streets.
If the condemned survived, he would be given a glass of water and then had his head smashed underneath the elephant’s foot. This was considered getting off lightly, because in some areas elephant executioners were meant to prolong the suffering of the condemned by throwing him in the air or crushing the limbs first.
The second method (used in medieval India) involved using blades. The elephants would have their tusks covered with sharp blades, and then strike at the condemned and throw them to the ground. After that, the elephant would either cut him to pieces, or (by order of the sultan) leave him on the ground, where he would be stripped of his skin.