On the Consolation, written as Boethius awaited execution in 524 CE.
Do bad things really happen to good people? Boethius, surprisingly, says no, for Stoic (anything that can be taken away can’t be of central importance; you can’t lose your virtue in this way), Aristotelian (all things tend toward the good, and the best thing for a person is achieving his or her innate potential, which is to be virtuous), and Christian (God’s unknowable plan means that even the stuff that seems bad really isn’t) reasons.
Boethius imagines Lady Philosophy herself coming to him in his cell and reminding him of the philosophical perspective that (following Plato) gives him access to a higher realm of being than the one inhabited by goods like reputation and bodily freedom. This results in arguments like bad luck is really good, because when things go bad, that’s when two-faced Fortune reveals herself as the inconstant villain she is. Also (this should be familiar from Plato’s Republic), even if someone wicked seems happy, by definition wickedness rules out true happiness, and virtue is its own reward. Goods like pleasure, fame, and riches promise a sort of completion, but they don’t deliver; really, what we’re looking for is integrity of self, which is what virtue offers.
To hear more about the famous “How can we have free will when God knows all?” part of the book, check out John Marenbon’s appearance on ep. 119 of the History of Philosophy Without Any Gaps podcast. On the episode before that one, host Peter Adamson also gives more information about what ideas came from what past authors and about the circumstances that gave rise to Boethius’s imprisonment.