This is because of "state-dependent memory". State-dependent memory refers to the phenomenon when someone recaptures his/her memories only when he is in that same state when that specific memory was formed. Usually the term is utilized when referring to a drug induced state of consciousness more particularly alcohol etc, but is implicated to other non drug induced states as well.