So basically they were built because back then they believed in a after life.
Explanation:
“Pyramids were built for religious purposes. The Egyptians were one of the first civilizations to believe in an afterlife. They believed that a second self called the ka lived within every human being.“