This sounds like The Consolation of Philosophy by Boethius. It was written in 523 AD.
Wikipedia tells us the following about the circumstances of the work's composition:
The Consolation of Philosophy was written in AD 523 during a one-year imprisonment Boethius served while awaiting trial—and eventual execution—for the alleged crime of treason under the Ostrogothic King Theodoric the Great. Boethius was at the very heights of power in Rome, holding the prestigious office of magister officiorum, and was brought down by treachery. This experience inspired the text, which reflects on how evil can exist in a world governed by God (the problem of theodicy), and how happiness is still attainable amidst fickle fortune, while also considering the nature of happiness and God. It was described in 1891 as "by far the most interesting example of prison literature the world has ever seen."
This is the best-known Latin text from the sixth century and the only Early Medieval text I read while learning Latin at school.
Another candidate is the Apology of Origen, written by Pamphilus of Caesarea and Eusebius. Eusebius spent two years in prison; according to Wikipedia
While he was in prison, Pamphilus and Eusebius worked together on five books in defense of Origen.
This took place during the Diocletianic Persecution in the early 4th century. Boethius was not persecuted for being a Christian, but Pamphilus was. However, the transcript of the lecture says,
He [Boethius] was imprisoned for a year. In prison he wrote one of the most magnificent works of philosophy, of why we are alive and why we die. The Consolation of Philosophy. And then he was executed.