The Chassidic explanation for this is very lucid, and helps us understand the sources. See Tanya Igeret Hakodesh 11 for example.
- Good = meant to happen.
- Bad = not meant to happen.
This is because there is only one God, who is the cause and source of everything that happens (Yishayahu 45:5-7), the power of powers (see Ramban on Bereshit 1:1), and He is a purposeful, good God:
טוב־ה' לכל ורחמיו על־כל־מעשיו
Hashem is good to all: and his mercies are over all His creations. (Tehillim 145:9)
צדיק ה' בכל־דרכיו וחסיד בכל־מעשיו
Hashem is righteous in all His ways, and kind in all His deeds. (ibid 17)
So we conclude that
- Everything that happens is meant to be.
- Everything that happens is therefore good.
Therefore affliction and suffering are not "bad", they are just difficult. Another way to put it is that there is some good that is "sweet" and some that is "bitter", and therefore we pray for a good, sweet new year.
Why is some goodness bitter? Sin:
מִפְּנֵי חֲטָאֵינוּ גָּלִינוּ מֵאַרְצֵנוּ
We were exiled from our land because of our sins
Be'er Mayim Chaim Shemot 10:1 writes:
כי הנה כאשר הקב"ה שולח יסורין וצער על האדם, והאדם נותן דעתו ולבו
להשגיח על מה אירע לו כך והלא אין דבר בעולם שיעשה מעצמו והכל נגזר מן
השמים... ואם כן על מה עשה ה' ככה לשלוח עלי יסורין האלה לצערני והלא טוב
ה' לכל ורחמיו על כל מעשיו אם לא שרצונו אשר על ידי יסורין האלה אזכור
בבוראי יוצרי שאשוב לפניו בתשובה שלימה ולחזור לתורתו ומצוותיו לעבדו
בלבב שלם
ונמצא כאשר שם האדם זאת על לבו... ושש ושמח בראותו הטובה הגדולה שעשה לו
אלהים להשגיח עליו ולפקח על עניניו... ולקרבו אצלו כחיבת אב על בנו,
וכמאמר הכתוב (משלי ג', י"ב) כי את אשר יאהב ה' יוכיח ואומר (תהלים צ"ד,
י"ב) אשרי הגבר אשר תיסרנו יה. הנה ודאי אשר זה המכה היא לו רפואה שלימה
וטובה גדולה וחסד גדול מאת ה' לרפאותו רפואת הנפש להיטיבו באחריתו
When Hashem sends suffering and pain to a person, and the person
notices and thinks about why this has happened to them, knowing that
nothing in the world happens by itself, and all is decreed from
Heaven... [He will ask] why did Hashem do this to me, sending these
difficulties to make me suffer? Is Hashem not "good to all, and His
mercies are over all His creations"? It must be that His will is
through these sufferings I will remember my Creator, and repent before
Him with a full teshuva, and return to His Torah and His mitzvot
and serve Him with all my heart.
When a person takes this to heart... they will be happy recognising
the great good that Hashem did for them, and the fact that He is
looking after them and being concerned with their affairs... bringing
them close to Him with the love of a parent for a child. As it is
written "For the one whom Hashem loves, He reproves" (Mishlei 3:12);
and it says: "Fortunate is the person whom Hashem afflicts" (Tehillim
94:12). This blow is a great kindness and healing from Hashem, healing
the person's soul and assuring their ultimate good.
There is also the concept of testing and refining. Not only does that allow us to gain reward for actions rather than merely the potential/thought/character, but it also improves our potential/thought/character (see Ramban and Ran on Bereshit 22:1)
Note how this modifies our understanding of typical examples: "he didn't board the plane because he forgot his tefillin, and therefore survived 9/11". They are not meant to imply that if he had gotten on the plane, ch'v, that would have been "not meant to be"; bad. If we conclude that, we've missed the entire lesson. The small suffering of missing a flight, the large suffering of losing one's life tragically, are both the same: they are meant to be and for the ultimate good. There's no two way street because there is only one way!