Some people say that the Holy Roman Empire had a lot of royal families. But at anyone time there is only one royal family per kingdom. In the earlier middle ages the Holy Roman Emperor was sometimes the over lord of several different European kingdoms with their own royal families.
The previously more or less hereditary positions of king of Germany and King of Italy or Lombardy were united with the position of Emperor in 962 when Otto I the Great, King of Germany and Italy, was crowned Emperor. The previously hereditary position of King of Arles or Burgundy was united with the position of Emperor in 1032.
So the Holy Roman Empire, and the Kingdom of Germany within it, didn't have lots of royal families.
What Germany did have a lot of was princely families. The princes (fursten) of the Holy Roman Empire were individually the first men in their principalities and collectively the first men in the Empire as a whole.
A noble counted as a prince of the Empire if he ruled an immediate fief directly subordinate to the emperor and had one of the princely titles which ran from lowest to highest as:
Princely count.
Landgrave.
Margrave.
Count Palatine.
Prince (Furst in German).
Duke.
Grand Duke.
Archduke.
A number of states and fiefs were also ruled by clergy, including Bishops, Archbishops, Abbots, and Abbesses, and some of them counted as princes of the Empire.
There were also hundreds of small immediate fiefs ruled by the imperial knights, who didn't count as princes. And there were a number of Free Imperial Cities.
And of course there were many fiefs ruled by nobles who were vassals of other nobles and who thus didn't count as princes of the Empire.
In the earlier middle ages European royal families married with nobles in their own kingdoms and foreign nobles as well as with other royal families. But in the later middle ages and modern times the royal families of Europe married almost exclusively only members of other royal families, becoming a separate caste which has only begun to marry with other families in the last few generations. In fact in many countries royals who married beneath them lost the right to pass on the throne to their descendants.
But the princely families of the Holy Roman Empire and Germany were the exception to that rule. They were considered much higher than nobles with equivalent titles in other European countries and high enough to intermarry with royal families, in part because they continued to rule principalities when most other nobles had lost their right to rule fiefs.
If European royal families had considered the German princely dynasties to be beneath them and not suitable marriage partners, they would have had a hard time finding suitable marriage partners, since there were usually only about ten separate catholic royal families in Europe in the later middle ages. When royal families stopped marrying with ordinary nobles in their kingdoms and foreign kingdoms and became a separate royal caste, they had to include the German princely dynasties within that caste in order to have enough suitable potential marriage partners.
After the Protestant Reformation caused a split between various Protestant denominations and the Roman Catholic Church, it became rare for royalty to marry members of the other side of the split. Thus it became even more necessary for European royalty to consider German princely families of the same faith as equal and valid marriage partners in order to have enough potential marriage partners.
Thus as a result of those intermarriages, it became possible for a person to inherit both a principality within the Holy Roman Empire and a kingdom outside it. For example, for about half a year in 1762 there were 10 persons who ruled both fiefs and principalities within the Holy Roman Empire and kingdoms or nations outside of it.
Which European nation had the most kings in the 18th century?1
How did member states of the Holy Roman Empire justify only including part of their land inside it?2
After the fall of the Holy Roman Empire in 1806 there were tens of former principalities in Germany which were now independent states, even though only a minority of their rulers took the title of king. And many of those states remained as semi independent states in the German Empire between 1871 and 1918. So until 1918 Germany had many reigning princes and dukes who were considered almost the equal of royal families in other countries, as well as mediatised (formerly ruling) families which were still considered to be of almost royal rank.
Thus during the 19th century many members of the German princely dynasties married into European royal families and sometimes inherited their thrones, while other members were considered, and sometimes selected, to become the new monarchs of newly independent countries.
English or Spanish or French nobles wouldn't have been considered to become the monarchs of new kingdoms because their status was so much lower than that of the almost royal status of the German princely dynasties.
So that is why the majority of the European royal families in the 19th and 20th centuries were descended in the male line from royal or princely dynasties ruling in Germany.