Goodness That Does Not Always Feel Good(Masechet Berachot Daf נד: Perek 9 Siman 16)
(condensed from Ein Ayah, Berachot 9:16)
Gemara: What beracha does one make when he survives a dangerous situation? “Blessed … who granted good things to those who are culpable.”
Ein Ayah: One who survived a bitter, dangerous experience when Hashem removed the normal Divine order of affairs has special lessons to learn along with the thanks he is to give. He should learn that it is not proper for man to ask for more than what he deserves, and he should be happy with what Hashem gives him.
The hoda’ah (usually translated, thanks) includes two parts. One is the viduy (admission, which comes from the same Hebrew root). One should realize that he was wrong for not being appreciative enough of his lot before the difficult, dangerous times came upon him. Hashem is kind in that He “grants good things to those who are culpable” for complaining about His wisdom and kindness. In fact, Hashem show his kindness specifically by bringing on the harsh situation that can serve as rebuke for man, encouraging him to improve himself.
The second, then, is to be thankful for his lot and recognize how Hashem was actually kind to him all along. That is what is meant by the pasuk (in Tehillim 107, upon which Birkat Hagomel is based): “They will thank Hashem for His kindness”, specifically after the hard times helped him morally. Only Hashem, who sees into his heart, knows how much help it was. The pasuk continues with “and for His wonders to mankind,” which relates to the wonderful phenomenon of keeping people within limits. This includes the discipline of social apparatuses, as we say that it is Hashem who grants kings their statuses.