This is called a lucid dream, although lucid dreams usually come with the realization that what you are experiencing is a dream.
They are caused by being in a lighter than usual state of sleep during REM. In this state, more parts of the brain are active then usual REM. This allows sensory input into the dream, and causes the high detail of the dream.
If you don't like them, try cutting down on caffeine, and making it darker and quieter while you sleep.
If you like them, try having a little caffeine, maybe a coke, before bed. Also, catnip, mint, cinnamon, nutmeg, and poppy seeds are all helpful. I find that if I combine a tablespoon of each of these herbs with a teaspoon of cocoa, and a tablespoon of sugar and put it all in the food processor; it makes a nice brown/orange spice, which is quite good on warm milk.