It’s usually because you wake up during the dream, or right after. This is during REM sleep. When you wake up then, the memory is still fresh in your brain. If you sleep through the night without waking up, you’re more likely to forget them by the morning.