You're having what are known as "lucid dreams" (formerly known as "night terrors"), they are very common. You're probably fairly young. They tend to go away as you get a bit older. They're caused by your brain's ability to paralyze your body getting kinda out of sync. No biggie, but it can be scary. The basic idea is that your brain has to paralyze your body during REM sleep, lest you physically act out your dreams, and injure yourself. Sometimes, the brain jumps the gun, and the paralysis happens during "twilight sleep" rather than the REM phase.
You should probably talk with your physician, I think I read about a med that takes care of it. (This is not "mental illness" of any kind at all -- it's more on the order of a migraine headache, but with different symptoms.)