It's because cheese takes a while to properly digest. While you are digesting, you are performing a bodily function (so to speak - maybe task would be a better word) and so your brain is active. If you eat something heavy and then fall asleep, your brain remains active during the digestion process, thus giving you very vivid, crazy dreams. When your brain is relaxed, the less wild the dreams.
Eating anything before you sleep is bad for you, as your brain does not shut down properly until all the processes are finished. Therefore, you may be asleep for 8 hours, but your brain will have had much less time than that to "charge up" again for the next day.