As @FireMadeFlesh said, your memory is stopped while you are asleep. Or rather, your long term memory is not at work. Short term memory is still there. That is why we remember things for a moment and then they are gone.
In order to remember dreams for a longer time, you have to make an effort. As soon as you wake up, you have to go over the dream in your mind, as much as you can. Replaying it. This allows you to transfer short term memories into long term ones.
A lot of people keep dream journals for this purpose. You quick write down the memory as soon as you wake. This has the added benefit that if your long term memory is still too sleepy, you have the written record to remind you.
If a dream is shocking enough, it may transfer over to long term memory whether you try to make it happen or not. My guess is that this kind of shock somehow wakes you a bit, allowing things to move into long term memory.