And the thinking was that if humans did their jobs then the pantheon of gods would maintain cosmic order, and since the pharaohs became gods upon their death, it made sense to please them even unto pyramids.