This is a midrash from Kohelet Rabbah 7:16, Tanhuma, Parashat Mezora,1; Yalkut Shimoni, I Samuel, Chapter 121 and the Rambam in Guide for the Perplexed Part 3, Chapter 39. See also Me’am Loez Anthology on Exodus, 21:14
Rav Hirsch points out in Mishpatim 21:14 that it is a commandment to put a murderer to death and it is not allowed to show him "mercy".
There is an interesting article applying this to modern times which quotes these sources.
“He Who is Compassionate to the Cruel
Will Ultimately Become
Cruel to the Compassionate”
This notion, that displaying an attitude of mercy towards the wicked
who deserve severe punishment involves acting cruelly towards the
general public, can be found in the words of Maimonides in his book
The Guide of the Perplexed.2 In reference to the verse (Exodus 21:14),
“If a person willfully schemes to kill his neighbor – he shall be
(even) taken from my altar and put to death”, Maimonides writes that
the wicked and calculating person (who killed intentionally and was sentenced to death) – if he seeks sanctuary among us, we must not
provide him with asylum and not have mercy upon him...because
compassion towards the wicked – is cruelty to all beings.
Regarding the verse located in the chapter discussing Saul’s war with
Amalek (I Samuel 15:9), “And Saul and the nation spared Agag,” the
Midrash says (Tanhuma, Parashat Mezora,1; Yalkut Shimoni, I Samuel, Chapter 121.):
R’ Elazar said: One who becomes compassionate to the cruel will ultimately become cruel to the compassionate, as it is written, “And
Saul and the nation spared Agag and the best sheep and cattle.”, and
it is written (Ibid. 22:19) “And Nov, the city of priests, he smote
with the edge of a sword.”
As we know, King Saul was commanded by the prophet Samuel: “Go and
smite Amalek and confiscate all that is theirs” (I Samuel 15:3). This
commandment stemmed from the Torah commandment to erase the memory of
Amalek (Deuteronomy 25:19), however, in the hearts of Saul and the
nation, compassion on Agag, King of Amalek and on the best sheep and
cattle, was aroused, and as a result, Saul refrained from completely
fulfilling the words of the prophet. In this regard, the Midrash
states that one who becomes compassionate to the cruel will ultimately
become cruel to the compassionate as King Saul acted compassionately
to Agag (the cruel) and ultimately became cruel to the compassionate,
in the guise of the people of Nov, the city of priests, whom Saul
killed wantonly because he suspected them of having assisted David.