I'm convinced that pyramids were built more as bunkers than as tombs. Sure they were used as such, but consider their features and utility.
High-ground gives archers range, and long line of sight. Horses couldn't traverse the steep surfaces, and foot solders would have to fight uphill. Traps and secret passages make navigation a daunting task. Stone construction prevents arson and render any sort of siege weapons useless. Food and novelties ensure a long stay is possible.
Rulers of these ancient cultures often had invading armies and their own subjects to to hide from. Pyramids seem like the most practical solution to this problem.
I'll bite. I'm assuming you mean Egyptian pyramids, as that architecture has been found across the globe.
May I point out that timber is pretty scarce in the desert and so stone was really the only option.
The high ground for archers is an interesting thought, but there's not really any area for them to amass and be defended from opposing projectiles.
Finally, I don't recall hearing of any archeological findings of weapons and armor near the base. If it were indeed a bunker, it would seem they were never used for such. Which begs the question of why make more?