Why do we sometimes remember our dreams, but sometimes not?

This is a very good question and I’m afraid it is one for which there is no satisfactory answer based on our current understanding of the brain. One thing studies have told us, though, is that dreams seem to happen more vividly and frequently during the REM (Rapid Eye Movement) stage of the sleep cycle, which tends to occur
roughly four to five times in a normal night’s sleep.

It has been reported by several studies that you are much more likely
to remember the dream you were having if you are woken in the middle of this REM cycle. So if you would like to remember your dreams more frequently, you could try setting your alarm clock to go off in the middle of your REM sleep cycle (likely to be near the end of your night’s sleep) and write down what you remember.