Chemically, our body supposedly releases a tryptamine molecule dubbed Dimethyltryptamine. Upon release it is suspected to take you into REM sleep, where most dreams occur.
Why we dream is still completely unknown and needs more extensive research done in the field.
Fascinating stuff...great question!