Well to my take the being put in prison would be a karmic debt paying of sorts. Perhaps at one time I had put someone in prison or caused others to conduct themselves as in a prison in a past lifetime, or conducted myself as though others are prisioners. So that would be debt paying in a self fullfilling sort,(not outside agent of course but self caused) and thusly a necessary and good thing as when done it is done.
To use it for spiritual purpose would be the best thing possible considering the difficult circumstance, and that is a good thing.
So both of those are good but certainly it would be very difficult and certainly a bad circumstance to be in, as circumstances go.
But by my take any circumstance we find ourselves in(though I personally fear and dread certain circumstances) are fortunate circumstances if we end up utilizeing them for spiritual purposes.That is if it aids and enhances our understanding of thngs as they are, through our interaction with it(my add on pretty much states that). So If I was in that circumstances I would estimate it would ultimately be a fortunate one. Ultimatly disease and death will be far more painful circumstances than prision for most. Though prison would be very painful in many ways.
In some forms of Buddhism people do indeed self create such circumstances for spiritual learning purposes.And self create other circumstantial things such as acting like crazy people or inhabiting haunted places, wildernesses, enhancing fears diseases even utilizing death when it presents as circumstance. They may all be fortunate circumstances, as you may know.
Involuntarily, prison would be very challenging. But death is largly involuntary for the most part as are most diseases. So this subject lies close to me and my practice.
I personally(jesting) hope I have no such causes, prefering solitary wilderness sojurnes of the not so wild kinds in only moderately rough terrain encountering spirits of the mostly benign kind. But I remain very lazy and spiritually slothful. Those fortunate circumstances I hope to avoid, and let others have their benefit.
"This order considers that progress can be achieved more rapidly during a single month of self-transformation through terrifying conditions in rough terrain and in "the abode of harmful forces" than through meditating for a period of three years in towns and monasteries"....Takpo Tashi Namgyal.