IIRC, their society depended on it. During peacetime, it was a major economic engine paid for from the royal treasury, with the work starting as soon as a new pharaoh ascended the throne, and the labor provided steady work when agricultural activity stopped due to Nile flooding. Of course, it's only in hindsight with our modern understanding of economics that we can see how such an activity at face value not important to any basic survival need was in fact a key piece of the economic fabric.
> The Roman writer Pliny the Elder, writing in the first century AD, argued that the Great Pyramid had been raised, either "to prevent the lower classes from remaining unoccupied", or as a measure to prevent the pharaoh's riches from falling into the hands of his rivals or successors.
This was the Pliny view.
Aka, it was a jobs program.
It was a Keynesian anti-cyclic wealth distribution program.
The jobs did come and go as necessary to maintain stability. It was reasonably well paid, from money collected taxing the luckiest farmers at the good times, stored as a community project.
It's really impressive how the Egyptians created this kind of organization and maintained it for thousands of years, when no government seems to be able to maintain something similar for a decade today.
If only our current leaders could have the vision to build robust infrastructure