Why do we dream? - Amy Adkins - YouTube
Not being limited to the rules of conventional logic, the mind can create infinite scenarios to help you find solutions that you wouldn't think conscious.
This is how August Kekule discovered the structure benzene molecule. Also, this is might be why is better to take a decision after you've slept on it.