The music for the “Wilhelmus” goes back to the 16th century and gets its inspiration from a cavalry fanfare or trumpet call, it is uncertain as to who originally wrote it; the first appearance of the melody is in the “oude Geuzenlied” in 1581. It has a common origin with the Dutch national anthem of the same name, which also dates from the same time period.
The melody was first used in Luxembourg on the occassion of the visit of the Dutch King William III and Queen Emma in 1883. Some years later, the anthem was played for Grand Duke Adolphe of Luxembourg along with the national anthem.
The use as a definitive anthem for the Luxembourg royal family dates to 1919 when Nikolaus Welter decided to create an anthem for the house of Luxembourg-Nassau-Bourbon for the occassion of the marriage of Grand Duchess Charlotte and Prince Felix. (Shortly after, the first stanza was dropped, which had many references to contemporary events of that time, leaving us with the anthem now in use.)
The anthem is played when one of the members of the grand ducal family enters or leaves an offical ceremony within Luxembourg.
Special thanks to: Gal Ben Kochav for some of this information.