I believe it has been established that these places were built for astronomy and worship purposes. There were many false religions back in ancient days, just as there are now, and most of them worshiped the heavens (sun, moon, star patterns as even back in ancient times Orion and other constellations were well known). We know this from ancient writings in the bible and other writings by the Sumerians, Babylonians, and Greeks.
Any people group who did not know Almighty God, the Creator of this world and all that is in it, worshiped false gods such as Baal, Astarte, Isis and Anu. Many worshiped and deified ancestors such as Woden. And many cultures worshiped nature and had a pantheon of gods to depict various items in nature (river, mountain, sun, etc).
Many of these false religions are still alive today under the guise of new names, or are a continued worship from ancient times (such as Taoism).
It is fascinating to know that our ancestors were not just dumb cavemen or hut dwellers, but highly intelligent people who created and built such amazing structures all over the world that defy the knowledge of today, Places such as those you mentioned, the Great Pyramids, Chichen Itza, and Moai (statues on Easter Island), to name just a few.