One who hears thunder while in the bathroom, can he make the appropriate beracha when he leaves the bathroom, even if it’s 5 minutes later?
Five minutes later would be too late to make the berachah. The berachah must be made within the time of toch kedei dibbur, which is a matter of seconds after the event.
The Yerushalmi (Berachos 9:2) writes that one who sees lightning while in the bathroom, and is able to hurry out within toch kedei dibbur, should hurry out and recite the blessing.
A number of rishonim (see Ramban and other rishonim, Pesachim 7b; Rosh, Berachos Chap. 9, no. 13) understand this to mean that one cannot make the blessing after the time of toch kedei dibbur has elapsed. This halachah is ruled in the Shulchan Aruch (Orach Chaim 227:3).
It is noteworthy that the Taz (227:2) disagrees with the ruling, and writes that the blessing can be recited later. He explains the Yerushalmi in a different light: If one can hurry out within toch kedei dibbur, this is ideal, and one should do so; if one cannot, there is no need to hurry out, and one can leave the bathroom at one’s leisure, and make the blessing after one leaves.
However, as noted above, the rishonim do not understand the Yerushalmi in this way, and the halachah follows the ruling of the Shulchan Aruch, according to which the berachah may only be made within toch kedei dibbur.
Note that the discussion above is stated with regard to lightning; the same principles apply to thunder