Applying the death penalty to heretics happened at a time when the Church and society in general were essentially the same thing, since everyone was Catholic. The kind of heresy that was punished with death had severe social consequences and generally involved encouraging active rebellion against both Church and state, to such an extent as to threaten the peace and lives of society as a whole.
Archbishop John Hughes, who was Archbishop of New York in the 19th cenury, had to answer the accusation that Catholics in government would punish and even execute Protestants in the US based on a concilliar canon from the middle ages authorizing the execution of certain heretics (the Albigensians). He responded as to why such heretics were actually put to death:
[quote=Archibshop Hughes, debate with John Breckinridge] *Let any man apply the doctrines of the Albigenses, simply on two points, viz. the tenet that the devil was the creator of the visible world ; and that, in order to avoid co-operation with the devil in continuing his work, the faithful should take measures by which the human race should come to an end ; and then say whether those errors were merely speculative. They were, on the contrary, pregnant with destruction to society. Was it persecution, or rather, was it not self-preservation, to arrest those errors? We shall see presently, however, that these men, like the Calvinists in France at a later period, took up the sword of sedition, and wielded it against the government under which they lived. We shall see, that long before the canon of Lateran was passed, their course was marked with plunder, rapine, bloodshed. And if so, it follows that their crimes against society springing from their doctrines, constitute the true reason of the severity of the enactment against them. *
St. Robert Bellarmine, his work De Laicis, explained how this was also only done after every other measure failed to protect society from such heretics:
[quote=St. Robert Bellarmine] Secondly, experience teaches that there is no other remedy; for the Church proceeded gradually, and tried all remedies; first, it fines, then exile, finally, it was driven to the penalty of death; for the heretics show contempt for excommunication and call them “cold thunderbolts;” if you threaten the penalty of fines, they neither fear God nor revere men, since they know that ignorant people will be found who will believe them and feed them. If you confine them to prison or send them into exile, they will corrupt their neighbors with their speech and those who are far away with their books. Therefore, there is only one remedy, send them timely to their place.