Trace amounts of DMT have been found to occur naturally in humans and other mammals. However, "the natural function of its widespread presence remains undetermined."
The idea that DMT is produced by the Pineal gland and is released prior to death or near death came from this guy Rick Strassman
Rick Strassman - Magical Egypt - Afterlife - DMT - Dimethyltryptamine"Basing his reasoning on the unreferenced and unsupported statement that all the enzymatic material needed to produce DMT is found in the pineal gland (see evidence in mammals), and moreover in substantially greater concentrations than in any other part of the body, Strassman has speculated that DMT is made in the pineal gland. Currently there is no published reliable scientific evidence supporting this hypothesis and as such, it is merely a hypothesis."
The Parietal Eye
"In some vertebrates, exposure to light can set off a chain reaction of enzymatic events within the pineal gland that
regulate circadian rhythms. Some early vertebrate fossil skulls have a pineal foramen (opening). This correlates with the physiology of the modern "living fossils," the lamprey and the tuatara, and some other vertebrates that have a parietal organ or "third eye," which, in some of them, is photosensitive. The third eye represents evolution's earlier approach to photoreception. The structures of the third eye in the tuatara are homologous to the cornea, lens and retina, though the latter resembles that of an octopus rather than a vertebrate retina. The asymmetrical whole consists of the "eye" to the left and the pineal sac to the right. "In animals that have lost the parietal eye, including mammals, the pineal sac is retained and condensed into the form of the pineal gland."
Many people have probably already heard of this, but Renes Descartes called the Pineal gland the ""seat of the soul". Although his theory has been heavily criticized.