Presumably, the tombs of pharaohs and other royals were considered sacred places in the ancient Egyptian religion. Yet, we are told that these tombs were looted frequently in antiquity.
Who was looting these sites? Was it Egyptians who did not believe in the religion, believers who were very desperate in times of disruption, or was it foreigners who were visitors/infiltrators or who were part of an invading force? You always hear that these tombs were looted, but there never seems to be any discussion about who was doing it.
Also, as a follow on if anybody has any information about this, are there any records of people being caught in the act of looting? If so what sorts of punishments did they face?
To begin with what we do know, I wrote about tomb robbing in the New Kingdom in Who were the grave robbers of ancient Egyptian tombs? Do we know anything about them at all? Most of the New Kingdom royal tombs had been plundered by the end of the 20th Dynasty, about 400 years after the first tombs in the Valley of the Kings, and tomb robberies were so prevalent in that period that the administration created a commission to investigate the condition of the tombs.
Unfortunately, we know much less about the plundering of the Old and Middle Kingdom royal tombs, though the recycling of materials in Middle Kingdom tombs suggests that the Old Kingdom pyramids had already been plundered by the 20th century BCE. For example, the pyramid of Amenemhat I of the 12th Dynasty contained blocks from the pyramids of Khufu, Khafre, Unis, and Pepi II (dating 300-500 years earlier). For more on this, see Goedicke's Re-Used Blocks from the Pyramid of Amenemhet I at Lisht.
The burial of Hetepheres, the mother of Khufu, is an unusual exception. When archaeologists discovered it in the early 20th century, they found splendid jewelry, the remains of a carrying chair, a bed canopy, and even a mosquito net. Reisner, the director of the excavations, was particularly excited about the discovery of a sarcophagus, as it seemed they had found the body of one of the members of the royal family. When it came time to open the sarcophagus in 1927, Reisner was joined by a large group of dignitaries excited to meet this ancient Egyptian queen. Unfortunately, the sarcophagus turned out to be empty, as Reisner dryly noted. ("Gentlemen, I regret Queen Hetepheres is not receiving.") There have been several competing interpretations of the tomb. The earliest interpretation, and still the most popular, is that the tomb was the designated burial place of Hetepheres. At some point in the reign of Khufu, thieves broke into the tomb and made off with most of the burial goods, including the body of Hetepheres. Rather than incur the wrath of the king, the officials in charge of the tomb resealed it and ignored the theft. A competing theory is that Hetepheres was moved to another tomb upon its completion and left some of her burial items behind in her temporary tomb.
Unfortunately, we know very little about the punishments for convicted tomb robbers since the tomb robbery papyri focus almost exclusively on witness examinations rather than sentences. It is highly likely that the punishment was death, however, and indeed Papyrus Mayer A records a man who proclaimed his innocence and insisted that he had no desire to seek death by robbing a tomb.
"I saw the punishment which was done to thieves in the time of the vizier Khaemwaset! Am I the sort of man to go looking for death when I know what it means?"
Further reading
Chapter 1 of Affairs and Scandals in Ancient Egypt by Pascal Vernus contains a good summary of what we know about New Kingdom tomb robberies. For translations of the tomb robbery papyri, see The Great Tomb-Robberies of the Twentieth Egyptian Dynasty by T. Eric Peet.