The Queen's Guard and Queen's Life Guard (called King's Guard and King's Life Guard when the reigning monarch is male) are the names given to contingents of infantry and cavalry soldiers charged with guarding the official royal residences in the United Kingdom. The British Army has regiments of both Horse Guards and Foot Guards predating the English Restoration (1660), and since the reign of King Charles II these regiments have been responsible for guarding the Sovereign's palaces. They are not purely ceremonial, despite tourist perceptions. The Queen's Guards are fully operational soldiers.

What is the purpose of the royal guards? Let's have some stream of consciousness first.
The relevant sentence in the passage is: The Queen's Guard and Queen's Life Guard (called King's Guard and King's Life Guard when the reigning monarch is male) are the names given to contingents of infantry and cavalry soldiers charged with guarding the official royal residences in the United Kingdom. So, the answer is guarding the official royal residences in the United Kingdom.