Aquinas states:
"As stated above (1), it is lawful to kill dumb animals, in so far as they are naturally directed to man's use, as the imperfect is directed to the perfect. Now every part is directed to the whole, as imperfect to perfect, wherefore every part is naturally for the sake of the whole. For this reason we observe that if the health of the whole body demands the excision of a member, through its being decayed or infectious to the other members, it will be both praiseworthy and advantageous to have it cut away. Now every individual person is compared to the whole community, as part to whole. Therefore if a man be dangerous and infectious to the community, on account of some sin, it is praiseworthy and advantageous that he be killed in order to safeguard the common good, since "a little leaven corrupteth the whole lump""
An execution is a serious thing indeed. It is not always forbidden, but it should not be a common thing. And it is not justified just through the sin of a person; after all we are all sinners. It is not justified even through a gravely serious sin; because no one is beyond the hope of redemption. Rather, it becomes justified when it is necessary to protect the common good of the community; and even then only when it is administered by someone who has been granted care of that common good (i.e. no vigilante killings.)
Now the situation is complex, because there are questions over when killing is the only way to protect the community, who really has the care of the common good and so forth. But I would think that in most cases it would be better to imprision child molesters than to kill them.