But why would you need 5000 people in your line of succession?
You could ask the other way around: why not? Most of those 5000 people have no official role in the UK, no British title, no state funding, and it is highly unlikely that anyone outside the first 10 people in the line of succession will ever ascend the throne. So keeping them in the line of succession is in the worst case innocuous and, pragmatically, there is no gain in removing them.
I would say it is more a sign of the UK's failure to update its legislation. The other royal houses of Europe have in common the circumstance of hundreds or thousands of descendants residing abroad as a result of intermarriages between royal houses as well as emigration. The difference is that in most of the other royal houses, the majority of the foreign branches are excluded from the lines of succession to their respective thrones.
Which European monarchies explicitly limit succession to national citizens only?
In the case of Sweden, the Instrument of Government says that the King or Queen who occupies the throne under the Act of Succession is the Head of State of Sweden. The Instrument of Government also has a clause that requires the "Head of State" to be a Swedish citizen, but the Act of Succession properly makes no reference to citizenship, although princes and princesses of the Royal House must be “ raised in the realm”, It is unclear whether someone could then be King or Queen under the Act of Succession, but be barred from serving as Head of State for not being Swedish. The Royal Court doesn't seem to take chances though, so there is a policy apparently in place under which membership of the Royal House (including membership for people who marry into the Royal House) requires having or acquiring Swedish citizenship (see Chris O'Neill's controversy as a case in point). Note, however, that membership of the Royal House is different from being in the line of succession as there are members of the Royal House who are not in the line (e.g. Daniel and Brigitta) and, vice-versa, there are people in the line of succession who are not members of the Royal House (e.g. CP's and Madeleine's children).. The requirement of being raised in the realm , according to the Court, also applies to princes or princesses of the Royal House only, hence Madeleine ‘s children for example are allowed to be raised in the US and still retain their succession rights.
I don't think the Spanish constitution has any restriction either on the King of Spain being a foreigner although there is a requirement that regents, when chosen outside the RF, must be Spaniards. I don't know about other countries like Belgium, Denmark or Norway, but normally restrictions are only that the monarch cannot be simultaneously the sovereign or Head of State of another country without parliamentary consent, or cannot be permanently out of the country for a maximum period of time without consent, or must have been raised in the realm, but there might be no specific references to nationality or citizenship status.
It seems that the most common mechanism that European monarchies use to cut down the line of succession, in addition to religious tests and exclusion of people who contract unapproved marriages, is actually to reset the line from time to time restricting it to the descendants of a recent monarch only, e.g. King Christian X and Queen Alexandrine in Denmark, King Juan Carlos I in Spain, or King Carl XVI Gustaf in Sweden. Over time, barring other forms of exclusion, the line of succession will keep growing exponentially in those countries too unless it is reset again. Only Norway and the Netherlands have explicit proximity of blood clauses involving the latest monarch.
PS: As ILuvBertie likes to remind us, in the case of the UK, the debate on a nationality clause is actually irrelevant as, in practice, all legitimate descendants of Sophia of Hanover are automatically eligible for UK citizenship. I don't think recent Immigration and Nationality Acts have changed that.