A dorsal eye is ancestral for chordates. Amphioxus has a light-sensitive spot on the top of the head region. Later with the evolution of the three-part brain, two eyes evolved on the top on an assymetrical axis, the one forward to the right and the other back to the left. At a time also they became symmetrical and the lateral eyes developed for the midbrain. Mature lampreys have four eyes. Hagfish became deep see animals, so their vision deteriorated. In later vertebrates, the back eye atrophied to make the still photoreceptive pineal gland, while the front became the parietal eye. All later fish had it. Both chondrichthyes and osteichthyes had it. Sarcopterygians related to tetrapods had it. Early tetrapods had it. Sauropsids had it, synapsids had it. And not only they had it, but it was in a large socket. Then it started disappearing. It seems whenever a lineage tended towards nocturnality, the first part of the visual system to go was the parietal eye. Archosauromorphs are presumed to have passed from a short nocturnal phase in the late Permian, they lost it. Turtles lost it too, but we don’t know why. Later, different groups of lepidosaurs started losing it, like geckos, amphisbaenians, and snakes. Premammalian synapsids lost it as well in the Triassic. While before it was in a specially raised part of the skull (that is only in synapsids, was it to get higher from the hair?), suddenly it was completely lost, and today mammals are the only group that not only have a reduced, completely non-photoreceptive pineal gland, but they activate it by a very cumbersome way from the hypothalamus to peripheral nervous system and back to gland, and some species like cetaceans have greatly simplified or lost the gland completely.

The parietal eye in all modern species is either too small or rudimentary. Its function has been described as mostly part of the endocrine system, but there are also studies that link it with orientation. It is said that it can detect shadows from above, but I don’t know how much of it is true. Many reptiles will dive for cover if something passes from above, but do they detect it with their normal eyes, orwith the parietal eye? Many reptile keepers have noted anectodally such behaivior in diurnal lizards. My bearded dragon, for example, will run away when an aeroplane is approaching, but I don’t know if she sees it with the parietal eye or the lateral eyes.From the few studies I have read, the parietal eye projects to midbrain endocrine areas, not to cortical/hemispheric visual areas. But if they use it also for orientation or predator avoidance, wouldn’t it be necessary to connect to visual areas?

And I know that presence of parietal foramen doesn’t necessarily mean presence of parietal eye, but we cannot deny that most Paleozoic tetrapods had it, and sometimes quite large, unlike that of today? Then why it started to get lost? Is only nocturnality the cause, or other factors as well, for example vulnerability to injury, expansion of the brain? Also, why the loss of the parietal eye starts mainly around and after the PT extinction?

sorry but no-one seems to know the answer to your question.