While the purpose of cannabinoids in plants remains unclear, the most popular hypothesis suggests they act to protect the plant from insects, bacteria, fungi, ultraviolet radiation, and drying.
In humans, cannabinoids are ‘retrograde transmitters’ because they travel backward against the typical flow of neurotransmitters (such as serotonin, dopamine, GABA, and glutamate). In this sense, you can easily understand cannabinoids as a ‘flow-control’ mechanism.
For example, imagine a presynaptic cell whose function is releasing dopamine. Typically, cannabinoid receptors will be densely populated on this neuron close to where the dopamine is released. To avoid excessive stimulation, the tissue surrounding the postsynaptic neuron will synthesize a cannabinoid and release it. As this cannabinoid binds to the receptors on the presynaptic cell, dopamine flow reduces, and you achieve homeostasis.
This process highlights another critical difference of cannabinoids from traditional neurotransmitters (which the body manufactures and stores in the presynaptic vesicle for later use). Cannabinoids are thought to be instead biosynthesized as needed, and are an integral part of nearly all human tissues.