One of the most moving prayers of the Yom Kippur service, is אלה אזכרה, these I will remember, that is recited during Mussaf.
In it, the deaths of the עשרה הרוגי מלכות, or the Ten Martyrs, is described in graphic detail. In the context of the Avoda service, these stories are brought to show the results of our sins.
The message is that all of our suffering at the hands of tyrants through the ages, is directly because of our bad behavior. It can never be that for no reason at all, Hashem placed us at the mercy of cruel, evil oppressors.
At the same time that we learn that these ten saintly rabbis were being punished for the sins of Joseph's ten brothers, (Kabbalists claim that they were actually a reincarnation of the brothers!) we are also meant to gain inspiration from their faith.
We need constant reminders that our lives depend entirely on Hashem. Rabbi Akiva died a happy man as he was able to give his life knowing that he truly loved Hashem with his heart, soul, and body.
Although Rav Chanina Ben Tradyon was burned alive with a Sefer Torah, he saw only the parchment burn and the letters float towards heaven. Stories such as these are meant to inspire us with the knowledge that no force on earth can break the unshakable bond between Hashem and the Jewish people. We must connect with unshakable faith that our trusting in Hashem brings us the greatest happiness and peace of mind humanly possible.