[(Gen. 38:1) AND JUDAH WENT DOWN.] This is what Scripture says (Isa. 55:8): "FOR MY THOUGHTS ARE NOT YOUR THOUGHTS, NEITHER ARE YOUR WAYS MY WAYS." A parable of a king of flesh and blood who sits and judges a man, and the judge says to him: "Say whether you killed or whether you did not kill." If he says to him, "I killed," the judge puts him to death; but if he does not confess, he does not put him to death. The Holy One, blessed be He, however, is not so: whoever confesses, the Holy One, blessed be He, has mercy upon him, as it is said (Prov. 28:13): "BUT WHOEVER CONFESSES AND FORSAKES THEM SHALL OBTAIN MERCY." Rabbi Shimon ben Halafta says: The Holy One, blessed be He, said to Jerusalem, "For what reason did I bring all these judgments upon you? Because you said, 'I have not sinned,' as it is said (Jer. 2:35): 'BEHOLD, I WILL ENTER INTO JUDGMENT WITH YOU FOR YOUR SAYING, I HAVE NOT SINNED.'" But whoever confesses and forsakes shall obtain mercy. Thus (Isa. 55:8): "FOR MY THOUGHTS ARE NOT [YOUR THOUGHTS]," etc. Rabbi Yose ben Ketsartah said: Flesh and blood makes himself a path on a mountain or in a valley; can he possibly make one in the water? But of the Holy One, blessed be He, it is written (Ps. 77:20): "YOUR WAY WAS IN THE SEA, [AND YOUR PATH IN THE MIGHTY WATERS]." In every place that He wishes, He makes Himself a way.
Why God Shows Mercy to the One Who Confesses
Midrash Tanchuma Buber, Vayeshev 11:1
[וירד יהודה]. זש"ה כי לא מחשבותי מחשבותיכם ולא דרכיכם דרכי (ישעיה נה ח). משל למלך בשר ודם שהוא יושב ודן לאדם והדיין אומר לו אמור אם הרגת אם לא הרגת, אם אומר לו הרגתי הדיין הורגו, ואם לא הודה אינו הורגו, אבל הקב"ה אינו כן, מי שמודה הקב"ה מרחם עליו, שנאמר ומודה ועוזב ירוחם (משלי כח יג), ר' שמעון בן חלפתא אומר, אמר הקב"ה לירושלים על מה הבאתי עליך כל המשפטים הללו, בשביל שאמרת לא חטאתי, שנאמר הני נשפט אותך על אמרך לא חטאתי (ירמיה ב לה), אבל מי שהוא מודה ועוזב ירוחם, הוי כי לא מחשבותי וגו'. אמר ר' יוסי בן קצרתה בשר ודם עושה לו שביל בהר או בבקעה, שמא יכול לעשות במים, אבל הקב"ה כתיב בו בים דרכך [ושבילך במים רבים] (תהלים עז כ), בכל מקום שהוא רוצה עושה לו דרך.