The Great Pyramids have always captured our imagination. For medieval Muslims, they were a relic of a ancient age of knowledge; an edifice of magic, astrology, and the jinn.
A thread-
By the 9th century there were several theories for who actually built the pyramids.
One stated they were built by the last jinn king, ibn Jann who ruled in the age before humanity.
In this narration, the jinn were the original inhabitants of the world. They filled the earth with wonder and corruption in equal measure.
Eventually a great jinn war broke out in which the angels sided with the goodly jinn and drove out the wicked ones.
Though the jinn king died in the war, mighty ifrits and ghuls guard the pyramids still.
The ifits arrive as mighty zawbaa, or whirlwinds of sand while the ghul lead unwary humans into the desert so they may eat them.
The jinn use phantom fires, sights, and sounds to drive the visitors mad.