A few facts have become increasingly indisputable: The first is that the story of the antediluvian pyramids developed during the Dark Ages from a Late Antique antecedent that was told not of pyramids but of temples and tombs, which partially explains why, against facts, writers claimed down to the early modern period that the interiors of the three Giza pyramids were filled with endless chambers and hieroglyphs. (Another part may be by analogy with the more elaborately decorated Fifth Dynasty pyramids.) Another fact is that the story was originally told of Hermes Trismegstus and grew out of Hermetic literature of Late Antiquity, particularly the form that had been influenced by Judeo-Christian apocalyptic traditions, hence the strange detail that Hermes predicted destruction by fire or flood, a prophecy with Babylonian antecedents that was widespread in Jewish apocalyptic traditions in the intertestamental period before being canonized (so to speak) in the New Testament. (Translations of original texts here.)
Here’s where the information becomes a bit confusing. The geographic distribution of Hermeticism seems to coincide quite closely with the geographic distribution of the Jewish myth of the Pillars of Wisdom allegedly built by the progeny of Seth and/or Enoch. Weirdly, this isn’t simply due to Greco-Roman culture making room for both, for it extends far beyond the borders of Greco-Roman civilization. According to van Bladel, a document identifying Hermes as a prophet coequal with Enoch and Seth was found as far afield as Chinese Turkestan, and a hotbed of Hermeticism was ancient Iran. Van Bladel argued, convincingly I think, that Greco-Roman Hermetic texts were translated into Middle Persian, perhaps as early as the time of Shapur I (reigned c. 240-270 CE), and it was from these that the Arabic Hermetic legends emerged. This occurred because the Persians, being ethnocentric like most cultures, had come to believe that Alexander the Great had stolen ancient Persian wisdom and stored it in Egypt, where the Persian sage Ostanes started the process of recovering their patrimony through translation. Part of the reason for this belief was the Greek literature falsely attributed to the Persian mage Zoroaster, whom the Greeks recognized as the inventor of magic—and thus the reason that medieval Europeans equated him with Ham and the Pillars of Wisdom.
All of this is interesting because our oldest account of a version of the pyramid legend (which lacks pyramids) was composed by Abu Ma‘shar, who was born and raised in Khorasan, the eastern territory of Persia, and he spices his account with references to the Middle Persian literature that must have served as his source. (Characters are given with Persian equivalents.) The same story of Hermes predicting the destruction of the world by fire and flood and building temples to preserve knowledge must have continued independently in Middle Persian literature until the caliphs finished the job of translating and then destroying it, for Abu Rayhan al-Biruni, in the Chronology of Ancient Nations a century later, preserves a distorted Persian account of the pyramid myth, which tells all of the standard details, but replaces the Giza pyramids with “buildings of the kind of the two pyramids” located in Western Persia, with the antediluvian knowledge buried beneath the central Persian city of Isfahan. Hermes is similarly swapped out for the Persian culture hero Tahmuras. This story is quite obviously a derivative of the more familiar tale, and one meant to place Persia above Egypt as the center of ancient knowledge. Tahmuras was a suitable substitute, for like Hermes he was an ancient king, a mystical sage, a magician, and an inventor.
So the Persian connection shows one likely way the story entered into Arabic lore, but it doesn’t help us answer the question of where it came from, since the Persian material is a cul-de-sac spawned of Late Antique translations from Greek.
There is, though, negative evidence to be gained from this. These facts pretty well establish that the fusion of Hermes with Judeo-Christian apocalyptic thought occurred elsewhere, and before the Middle Persian source texts used by Abu Ma‘shar were translated from Greek. That puts us back in Hellenistic Egypt, and Abu Ma‘shar’s reference to Hermes creating the Temple of Akhmim to guard against the Flood helps us narrow this down a bit more. The Temple of Akhmim, the Hellenistic Panoplis, was a center for Greco-Roman Egyptian mysticism, as well as the site of Christian monasteries conversant in the Book of Enoch and other apocryphal, apocalyptic texts, fragments of which archaeologists found there. Specifically, the fifth or sixth century Akhmim Codex contains 1 Enoch 1:1-32:6, the section dealing with the Fallen Angels and the antediluvian wisdom, but it is unlikely to have been the first or only copy of the text on offer there. The Epistle of Jude preserves a quotation that agrees nearly verbatim with this fragment. In the medieval period, Akhmim was considered Hermes’ hometown, where he taught alchemy.
If Van Bladel is right that Greek texts were translated into Middle Persian around 250 CE, might be a smidge too early for a Christian presence at Akhmim. But maybe not. Others living there around that time seem to have known the Book of Enoch. We know that Zosimus of Panoplis, an alchemist, was versed in the Hermetic mysteries of his hometown of Akhmim, and he was also heavily influenced by the Book of Enoch and the Fallen Angels myth. Writing in his Imouth around 300 CE, he combined Hermes with the Watchers, and attributed the origins of alchemy to the Watchers and the preservation of knowledge of it to Hermes. If Zosimus’ “sacred books” of Hermes were intended to be the Book of Enoch, which his description seems to summarize, this might even be the earliest known equation of Enoch with Hermes, later a staple of Islamic lore.
Around the same time, the Hermetic Perfect Discourse (a.k.a. the Aesclipius) reflects at a bit of a distance the Enochian prophecy of fire and flood, granting Hermes the same knowledge the Jews attributed to Enoch. In 363, even the anti-Christian emperor Julian the Apostate noted that there was a clear comparison to be made between Hermes, the Hebrew prophets, and (appropriately enough) the Babylonian Oannes, who unbeknownst to him, was a reflex of the Seven Sages who likely served as the model for the Watchers in the first place. Around 400, the Christian abbot Serenus of Egypt claimed (Cassian, Collationes 8.21) that the Watchers’ evil wisdom, now attributed to the magician Ham, had survived the Flood by being buried, much the way Hermes and the Egyptians supposedly kept their wisdom safe according to the contemporary Ammianus Marcellinus (Roman History 22.15.30), writing only a few decades earlier. Which direction the influence went, I could not say.
While I don’t have enough evidence to put the creation of the pyramid legend exactly at Akhmim, it looks like it must have developed in Late Roman or Byzantine Egypt, and the story of Hermes and his buried wisdom gradually became more similar to Enoch and the Pillars of Wisdom as paganism gave way to Christianity and then Islam and the two prophets were ever more closely identified.
The Surid story is a relatively straightforward euhemerizing in this reading, with Surid substituting for Hermes because, as Julius Africanus testified, in Late Antique Egypt Khufu (Suphis in the Greek of Manetho) was imagined to be the author of Hermetic treatises (a Greek alchemical work carries his fictional byline), and thus may have been identified with Hermes himself, or became a suitable substitute, much the way other writers made the fictional pharaoh ’Ankam into Hermes. After all, we know from Late Antique and Christian testimony about Alexander the Great (yes, him again) that he learned the secret of the Egyptian gods, which was that they were merely human beings. Therefore, identifying Hermes as the title of an ancient king would not have been that much of a stretch. Indeed, Abu Ma‘shar specifically tells us that Hermes was a royal title, like Caesar.