Can we treat sin with another sin? Matthew 18:9


  And if your eye causes you to stumble, gouge it out and throw it away.
  It is better for you to enter life with one eye than to have two eyes
  and be thrown into the fire of hell.


Now it is obvious that self-harm is a sinful act. I understand that the verse is not meant literally but I wonder if it can be justified in different situations. Even some saints used self-harm to prevent them from sinning in a different area of their life. (St. Francis throwing himself into bushes with thorns to deal with lust)

For example:
If a man is worried he might commit an adultery, is it ok for him to get castrated? There is a discussion going on whether to castrate sex offenders. It will protect our society and maybe even their families. Or maybe tell a lie to prevent harm if saying the truth could cause greater harm.
There are many other examples I could mention but I don't want to make them as a subject of my question but simply to ask: 
Can we treat sin with another sin? Or can one sin be justified as the mean to prevent another sin?
Ends do not justify means
No, it is never permissible to sin so that good may come about.
St. Paul wrote:

Rom. 3:8let us not do evil that there may come good

and

Rom. 5:20 &amp; 6:1where sin abounded, grace did more abound. […] [So] shall we continue in sin, that grace may abound? God forbid.

Grace is always sufficient to doing good:

2 Cor. 12:9My grace is sufficient for thee

Soul to be preferred over the body
Both the body and soul are goods, and it is against the 5th Commandment to do bodily or spiritual harm to oneself, but usually the body (a good) is against the soul (another good):

Gal. 5:16-17I say then, walk in the spirit, and you shall not fulfill the lusts of the flesh. For the flesh lusteth against the spirit: and the spirit against the flesh; for these are contrary one to another.

This is why the Church prescribes fasting and abstinence, for mortifying our evil inclinations.
Because we are dealing with two goods (body and soul), we must apply the principle of double-effect (cf. this Christianity StackExchange answer) and prefer the soul over the body:

Mat. 10:28…fear ye not them that kill the body, and are not able to kill the soul: but rather fear him that can destroy both soul and body in hell.

Tolerating evil to prevent greater evil or to do greater good
Sin can be tolerated in order to prevent a greater evil. For example, a ruler could tolerate the evil ideology of Islam because if he condemned it, it might excite Muslims to greater violence and make Christians lose their faith.
Addressing the question of &quot;Whether the rites of unbelievers ought to be tolerated?,&quot; St. Thomas Aquinas says:

…although God is all-powerful and supremely good, nevertheless He allows certain evils to take place in the universe, which He might prevent, lest, without them, greater goods might be forfeited, or greater evils ensue. Accordingly in human government also, those who are in authority, rightly tolerate certain evils, lest certain goods be lost, or certain greater evils be incurred: thus Augustine says (De Ordine ii, 4): &quot;If you do away with harlots, the world will be convulsed with lust.&quot; …