Regarding how melatonin might cause more vivid dreams. I found the theory put forward here quite plausible:
There are user reports that melatonin causes vivid dreams. Actually, all sleep aids appear to some users to produce more vivid dreams.
What is most likely happening is that the drug modifies the sleep cycle so the person emerges from REM sleep (when dreams are most vivid) to waking quickly – more quickly that when no drug is used. The user subjectively reports the drug as producing vivid dreams.
Regarding how melatonin might cause more vivid dreams. I found the theory put forward here quite plausible: