Ancient Egyptians believed that when the pharaoh died, he became Osiris, king of the dead. The new pharaoh became Horus, god of the heavens and protector of the sun god. This cycle was symbolized by the rising and setting of the sun.
Some part of a dead pharaoh's spirit, called his ka, was believed to remain with his body. And it was thought that if the corpse did not have proper care, the former pharaoh would not be able to carry out his new duties as king of the dead. If this happened, the cycle would be broken and disaster would befall Egypt.
To prevent such a catastrophe, each dead pharaoh was mummified, which preserved his body. Everything the king would need in his afterlife was provided in his grave—vessels made of clay, stone, and gold, furniture, food, even doll-like representations of servants, known as ushabti. His body would continue to receive food offerings long after his death
To shelter and safeguard the part of a pharaoh's soul that remained with his corpse, Egyptians built massive tombs—but not always pyramids.
Before the pyramids, tombs were carved into bedrock and topped by flat-roofed structures called mastabas. Mounds of dirt, in turn, sometimes topped the structures.
The pyramid shape of later tombs could have come from these mounds. More likely, Egyptian pyramids were modeled on a sacred, pointed stone called the benben. The benben symbolized the rays of the sun; ancient texts claimed that pharaohs reached the heavens via sunbeams.
-courtesy National geographic site