No, and Animandavya suffered for it.
If you are above fourteen years of age, it is not wise to kill an insect. That will be considered a sin.
https://www.sacred-texts.com/hin/m01/m01109.htm
Some thieves put their treasure in his home and Mandavya was wrongly accused.
"Vaisampayana said, 'There was a Brahmana known by the name of Mandavya. He was conversant with all duties and was devoted to religion, truth and asceticism. The great ascetic used to sit at the entrance of his hermitage at the foot of a tree, with his arms upraised in the observance of the vow of silence. And as he sat there for years together, one day there came into his asylum a number of robbers laden with spoil. And, O bull in Bharata's race, those robbers were then being pursued by a superior body as guardians of the peace. The thieves, on entering that asylum, hid their booty there, and in fear concealed themselves thereabout before the guards came. But scarcely had they thus concealed themselves when the constables in pursuit came to the spot. The latter, observing the Rishi sitting under the tree, questioned him, O king, saying, 'O best of Brahmanas, which way have the thieves taken? Point it out to us so that we may follow it without loss of time.' Thus questioned by the guardians of peace the ascetic, O king, said not a word, good or otherwise, in reply. The officers of the king, however, on searching that asylum soon discovered the thieves concealed thereabout together with the plunder. Upon this, their suspicion fell upon the Muni, and accordingly they seized him with the thieves and brought him before the king.
They even sentenced him.
The king sentenced him to be executed along with his supposed associates. And the officers, acting in ignorance, carried out the sentence by impaling the celebrated Rishi. And having impaled him, they went to the king with the booty they had recovered. But the virtuous Rishi, though impaled and kept without food, remained in that state for a long time without dying. And the Rishi by his ascetic power not only preserved his life but summoned other Rishi to the scene.
The king later asked for forgiveness.
After this, O monarch, the officers of justice, seeing him alive, informed the king of it. The latter hearing what they said, consulted with his advisers, and came to the place and began to pacify the Rishi. fixed on the stake. And the king said, 'O thou best of Rishis, I have offended against thee in ignorance. I beseech thee to pardon me for the same. It behoveth thee not to be angry with me.' Thus addressed by the king, the Muni was pacified. And beholding him free from wrath, the king took him up with the stake and endeavoured to extract it from his body. But not succeeding therein, he cut it off at the point just outside the body. The Muni, with a portion of the stake within his body, walked about, and in that state practised the austerest of penances and conquered numberless regions unattainable by others. And for the circumstances of a part of the stake being within his body, he came to be known in the three worlds by the name of Ani-Mandavya (Mandavya with the stake within).
The Brahmana later goes to Yama and questioned him
And one day that Brahamana acquainted with the highest truth of religion went unto the abode of the god of justice. And beholding the god there seated on his throne, the Rishi reproached him and said, 'What, pray, is that sinful act committed by me unconsciously, for which I am bearing this punishment? O, tell me soon, and behold the power of my asceticism.'
Yama explained that he pierced an insect.
bringeth in its train.'
Now, Mandavya asked when he did it.
On hearing this, Ani-Mandavya asked, 'O tell me truly when this act was committed by me. Told in reply by the god of justice that he had committed it, when a child, the Rishi said, 'That shall not be a sin which may be done by a child up to the twelfth year of his age from birth.
Mandavya later cursed Yama which is why he was born as Vidura.
The killing of a Brahmana involves a sin that is heavier than the killing of any other living being. Thou shall, therefore, O god of justice, have to be born among men even in the Sudra order.
He established at what age an act will be considered a sin.
And from this day I establish this limit in respect of the consequence of acts that an act shall not be sinful when committed by one below the age of fourteen. But when committed by one above that age, it shall be regarded as sin.'
However, Mandavya prayed to Shiva and he was no longer hurt as he told his story of praying to Shiva to Yudhishthira.
https://www.sacred-texts.com/hin/m13/m13a018.htm
"Mandavya said,--'In former times though not a thief and yet wrongly suspected of theft, I was impaled (under the orders of a king). I then adored the illustrious Mahadeva who said unto me,--Thou shalt soon be freed from impalement and live for millions of years. The pangs due to impalement shall not be thine. Thou shalt also be freed from every kind of affliction and disease. And since, O ascetic, this body of thine hath sprung from the fourth foot of Dharma (viz., Truth). Thou shalt be unrivalled on Earth. Do thou make thy life fruitful. Thou shalt, without any obstruction, be able to bathe in all the sacred waters of the Earth. And after the dissolution of thy body, I shall, O learned Brahmana, ordain that thou shall enjoy the pure felicity of heaven for unending Time.--Having said these words unto me, the adorable Deity having the bull for his vehicle, viz., Maheswara of unrivalled splendour and clad in animal skin, O king, disappeared there and then with all his associates.'