In the times of the Bet Ha’mikdash, a person who emerged safely from a dangerous situation was required to bring a sacrifice called a Korban Toda to express thanksgiving to the Almighty. After the Temple’s destruction, the Sages enacted a requirement to recite a Beracha – Birkat Ha’gomel – in place of the Korban Toda offering. Since we cannot bring sacrifices in the absence of the Bet Ha’mikdash, the Sages instituted a Beracha that one recites to express his gratitude to God in lieu of the Korban Toda.
As this Beracha serves in place of the Toda offering, its recitation must follow certain guidelines so that it resembles the sacrifice. For example, one must recite this Beracha while standing, and not while seated. A person who brought a sacrifice in the Bet Ha’mikdash was required to stand during the offering, and therefore one must also stand during the recitation of Birkat Ha’gomel, which comes in place of the Korban Toda.
By the same token, it is preferable not to recite Birkat Ha’gomel at night. (In truth, the custom in any event is to recite the Beracha when the Torah is read in the synagogue, which is done only during the daytime, but strictly speaking the Beracha does not have to be recited as part of the Torah reading.) Just as sacrificial offerings were not brought in the Temple during the nighttime hours, similarly, one should not recite Birkat Ha’gomel at night. Nevertheless, one who did recite Birkat Ha’gomel at night has fulfilled his obligation and does not have to repeat the Beracha.
One of the situations requiring the recitation of Birkat Ha’gomel is the safe release from captivity or imprisonment. Would this apply to a holding cell? Sometimes the police bring a person to the station for questioning and he is confined for several hours in a holding cell. This cell is not an actual prison, but rather a room where people are temporarily held. If a person was confined in a holding cell and then sent home, must he recite Birkat Ha’gomel?
The Be’ur Halacha (accompanying essays to the Mishna Berura, by Rabbi Yisrael Meir Kagan of Radin, 1839-1933) indicates that in such a case a person would not recite the Beracha. Since he was not actually "imprisoned" in the strict sense, but rather held for several hours, he would not recite Birkat Ha’gomel. However, Hacham Ben Sion Abba Shaul (Israel, 1923-1998), in his Or Le’sion (vol. 2, 14:41), disagrees. He argues that since during those several hours the individual has no control over his fate, and is instead entirely under the control of the police, this confinement qualifies as "imprisonment" with respect to Birkat Ha’gomel. He would therefore be required to recite Birkat Ha’gomel upon his release.
Summary: Birkat Ha’gomel must be recited while standing, and should preferably be recited by day, and not by night. A person who was released from prison must recite Birkat Ha’gomel, even if he was confined only temporarily in a holding cell.