I mean, it's a memorable way to go and demonstrates tremendous commitment, but this is something we usually see in religions deriving from India, where Agni is both a god and integral at a fundamental, philosophical, conscious level. (Buddhist monks, for example, famously used self-immolation to protest the Vietnam war.)
The exact manner of Heracles' death did not appear to be significant to early authors of the myth. In fact, even though both Homer and Hesiod mention the hero eventually finding his place amongst the gods1, neither explain how he achieved divinity. It seems the task of constructing a tale explaining Heracles' unique and somewhat bizare2 status as "hero god" was daunting, even to the likes of Homer and Hesiod.
Yet, although Heracles may not have been a protagonist in the works of the epic poets, in the 5th century BCE he was truly a panhellenic hero. The story of his death and deification was now an important one, one that could not remain untold. Audiences were already aware that Herakles had cheated death more than once, and that he would eventually ascent to Olympus. All that remained was an elaborate death scene, one that would be majestic enough to match the status of the hero and perhaps theologically significant enough to explain the transition from man to god.
Death by fire may seem like an excruciating way to go, however, it really is the most fitting choice. Before attempting to explain why I'd like to provide some context by quoting parts of the story as told by Sophocles in Trachiniae:
Now... do you know Zeus' sacred mountain Oeta?
Yes. I have often sacrificed upon it.
That is the place where you must carry me
with your own hands, and with what friends you choose.
There hew the wood of deeply-rooted oaks
and slash the trunks of wild male olive trees,
placing my body on a pyre made from them;
then take a brightly blazing torch of pine
and light the pyre. And do not moan and weep,
for if you are my son you will perform this
without a sigh or tear. If not, my curse,
even when I am dead, will weigh upon you.
Sophocles, Women of Trachis. Translation by Robert M. Torrance
Hyllus reluctantly agrees and constructs the pyre, and then places his father on it:
At last you speak well! Now perform this favor swiftly, my child, and place me on the pyre before the stinging spasm comes again. Make haste and lift me. Now I feel release from troubles, for my final end is here.
Nothing prevents fulfillment of these deeds, since you command it and compel us, father
The first question we must ask is if Heracles' death is in accordance with funerary customs of the era, as his deification would be even more inexplicable if his death was somehow sacrilegious. Although cremation had gone out of style in most parts of Greece, it was not entirely abandoned and was still the preferred practice in Athens. Furthermore - and perhaps more importantly - cremation was strongly associated with the Heroic Age. Even if it wasn't the favourite practice of the era, we can't ignore how the tale of Heracles' death parallels the deaths of the heroes of the Trojan War3.
Still, the hero's death is gruesome. He is burned alive after all. However, even though Heracles knows that his suffering will eventually end5, it is established in the tale that the pain from the poison is, for lack of a better word, unbearable. Out of context, his death appears dreadful. Considering the alternative, though, we may even say it's liberating. In some versions of the myth, the poison is said to slowly burn the hero's skin, making his death even more fitting. It doesn't add to the pain, it only accelerates the inevitable.
As for theological symbolisms, the most obvious one is that of sacrifice. Heracles specifically chooses Oeta - a mountain sacred to Zeus - as the scene of his death and provides elaborate instructions for the construction of the pyre. Both the location and the complexity of the pyre favour a ritualistic interpretation, a last offering of Heracles to the glory of Zeus.
Or perhaps the ritual is one of purification, one that intends to separate (or even liberate) the divine from the corporeal. This wouldn't be a new idea, as the notion of burning mortality away also appears in the story of Demophoon:
When she had so spoken, she took the child in her fragrant bosom with her divine hands: and his mother was glad in her heart. So the goddess nursed in the palace Demophoon, wise Celeus' goodly son whom well-girded Metaneira bare. And the child grew like some immortal being, not fed with food nor nourished at the breast: for by day rich-crowned Demeter would anoint him with ambrosia as if he were the offspring of a god and breathe sweetly upon him as she held him in her bosom. But at night she would hide him like a brand in the heart of the fire, unknown to his dear parents. And it wrought great wonder in these that he grew beyond his age; for he was like the gods face to face. And she would have made him deathless and unaging, had not well-girded Metaneira in her heedlessness kept watch by night from her sweet-smelling chamber and spied. But she wailed and smote her two hips, because she feared for her son and was greatly distraught in her heart; so she lamented and uttered winged words:
"Demophoon, my son, the strange woman buries you deep in fire and works grief and bitter sorrow for me."
Thus she spoke, mourning. And the bright goddess, lovely-crowned Demeter, heard her, and was wroth with her. So with her divine hands she snatched from the fire the dear son whom Metaneira had born unhoped-for in the palace, and cast him from her to the ground; for she was terribly angry in her heart. Forthwith she said to well-girded Metaneira:
"Witless are you mortals and dull to foresee your lot, whether of good or evil, that comes upon you. For now in your heedlessness you have wrought folly past healing; for -- be witness the oath of the gods, the relentless water of Styx -- I would have made your dear son deathless and unaging all his days and would have bestowed on him ever-lasting honour, but now he can in no way escape death and the fates. Yet shall unfailing honour always rest upon him, because he lay upon my knees and slept in my arms. But, as the years move round and when he is in his prime, the sons of the Eleusinians shall ever wage war and dread strife with one another continually. Lo! I am that Demeter who has share of honour and is the greatest help and cause of joy to the undying gods and mortal men. But now, let all the people build me a great temple and an altar below it and beneath the city and its sheer wall upon a rising hillock above Callichorus. And I myself will teach my rites, that hereafter you may reverently perform them and so win the favour of my heart."
Homeric Hymn to Demeter, translated by Hugh G.Evelyn-White
Lastly, a more practical, yet deeply theological, reason for death by fire is that no body remains. The story of the hero ascending to Olympus is much easier to sell, without a corpse left to rot behind6.
1 See Odyssey, Book 11 & Theogony, 950.
2 The apotheosis of Heracles presented unique challenges to his worshippers. For example, was he to be worshipped in a heroon, or a temple?
3 See, for example, the cremation of Patroclus in Iliad, Book 23.
4 Suicide is highly unusual for heroes, and is often associated with cowardice.
5 His death having been prophesized by Zeus in Dodona.
6 A corpse would require a burial, a cthonic ritual that by definition is antithetical to the idea of ascending to heaven.