There are four categories of people who need to thank G‑d for the kindness He has done for them with the “Blessing of Thanksgiving” (Birkat HaGomel): They include
a) One who has crossed the ocean (an overseas flight travel, etc.)
b) One who has crossed the desert
c) One who recovered from a very serious illness
d) One who was released from prison.
According to Jewish Halacha, regarding one imprisoned for money matters, it would apply only if he is imprisoned with shackles and chains, but if he is imprisoned in a way that there is no danger to his life, then he would not say the blessing. It would seem that in many of today’s prisons, one may still be in dangerous situations and may require a blessing upon release and a competent Rabbi should be consulted.