From the beginning of the Pharaonic period, Ancient Egypt was run as a theocracy. A theocracy is a form of government in which the government claims to rule on behalf of a god or deity. A powerful king would promote the belief that he had the support of the gods, so no one would try to remove him and risk the displeasure of the gods. From this grew the idea of divine kingship, that the king was the divine representative of a god on earth.
There are two theories for how the idea for divine kingship started. One is that a king spread a rumor that he'd had a vision in which the gods had told him he was their representative on earth. Another theory is that when a king returned home after an extended period, he found his wife pregnant. She might have said that a god, the king's father, had impregnated her to continue the divine line of kingship.
When the pharaoh was crowned, it was believed that the spirit of Horus entered into him as a guide. He also received the royal ka, or soul, which made him divine. When he died, the pharaoh's spirit would be merged with Osiris so that he could guide his successor. As a god, the king became a son of Ra, or Amun-Re in later years. Various festivals reinforced the king's divinity, such as the annual Opet festival, which renewed the king's union with his royal ka. The Heb-Sed festival, celebrated after thirty years, was intended to restore the king's vitality and confirm his union with the royal ka.
The symbols of the pharaoh associated him with the gods: the crook was to reward the innocent while the flail was to punish the guilty, the double crown showed his authority over the two lands, and the ureaus, or royal cobra, was the Eye of Ra, who would see all that the pharaoh did. The king was charged with settling legal disputes and leading religious rituals. He held the balance of maat, the rule of order over chaos. As long as he honoured the gods and obeyed their laws, all would be well.
Because of his status as a god, the pharaoh had a cult both during his life and after his death. This became more prominent during the New Kingdom. The king's cult rituals were very similar to other daily temple rituals. Statues were built to receive offerings, including statues of the king making offerings to his deified self. Royal cults were used to serve political aims as well. During a co-regency, when the successor was crowned before the death of the prior king, the elder ruler was often projected into a divine status. By the New Kingdom, the cult of the king began to focus on his divine birth, in that the king was not created from the seed of his father, but by Amun himself. Rulers such as Hatshepsut used this to legitimize their claim to the throne.
In the Greco-Roman era, the Ptolemies adapted the ancient Egyptian system of theocracy to support their right to rule. By the time of Ptolemy the Second, the king and queen claimed themselves to be gods. The notion of the sacred family evolved, in which the lineage of the Ptolemies was said to extend to Alexander the Great with Zeus as the divine ancestor. Ptolemaic rulers also had offering cults much as the ancient Egyptian rulers before them. The establishment of the brother-sister marriage springs from this Hellenistic form of divine kingship, set by the precedent of the marriage between Zeus and his sister Hera. It also had its practical purposes, to keep the wealth within the family and to prevent rivals from gaining power through marriage.