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.
Stone construction hinders siege weapons, but it does not make them impossible to destroy. Many siege weapons were used well specifically to destroy stone structures. The pyramids may have been an exception tough due to their excessively solid internal construction. There weren't frequent hollow chambers near the outside that could be easy targets for collapse, so they would be nearly impossible to siege. They just did not have any defense structures, no way to mobilize soldiers/archers, to use counter siege equipment, etc. so I don't see them as military buildings