Hashem’s Part in What Looks Bad(Masechet Berachot Daf מח: Perek 7 Siman 36)
(condensed from Ein Ayah, Berachot 7:36)
Gemara: From where [do we know] that as we bless Hashem for the good, we do so for the bad? For this the pasuk (in the context of Birkat Hamazon) says: “… that Hashem, your G-d, gave to you” (Devarim 8:10) – He is your judge with every judgment He makes, whether He uses the “good” approach or the harsh approach.
Ein Ayah: To fully appreciate Hashem’s manner of leading the world, one needs to know that Hashem has total power to act, in which case He could prevent any situation which we know as bad. Therefore, we know that everything we consider bad is and will eventually be recognized as totally good [according to its situation].
This is different than the philosophers’ approach that there is, by necessity, a physical element that cannot allow good things without bad ones. While they thereby “clear” Hashem of responsibility for the bad, according to them, one cannot bless Him for it either. However, the Torah approach posits that Hashem does all He desires, in which case, everything stems from a good and just judgment. In that way, He is referred to as our judge, who has the power to rule with straightness and wisdom. Therefore “bad” deserves a beracha just like “good” does.
This idea is written in the context of Birkat Hamazon because the need for food and connection to the material seems negative. However, this is what the entirely good Hashem decreed, and, therefore, all its elements must be good. We learn specifically from that point that everything that looks bad is actually part of a deep Divine plan.