I know that Charles XII of Sweden was killed while he was inspecting his soldiers on a trench, but it looks like royal families started to participate less in wars till a point that is almost no participation among the majority of families.
The major explanation i got is the most obvious: you can die in a war, and it can cost the succession line of your house.
But that doesnt makes sense to me: did the monarchs that took part of their wars through the annales of history never thought of that? Just later, some monarchs were like: "oh, I can die in war and mess up my family line, so Its better staying home". Just doesnt seem logic since earlier monarchs probably had come up with this and they still leaded their troops.
One reason as outlined in previous answers is that military technology and tactics changed over time. I assembled some links on this topic a while ago, the relevant parts of which I can repost here below:
There are this older thread by u/Bacarruda and two more recent ones (here by u/RustedBarrelKing and here by u/TreeShaun) which take a broad perspective and write some about the end of this expectation (the second of which even mentions the interesting fact that a head of state was killed in combat as recently as last year!).
There have been many answers on why leaders partook in battle in ancient and mediaeval warfare, which I can also repost should you be interested.
There are lots of good answers here already but I'll throw something else into the mix: the increasing professionalisation of both government and military command in the 17th, 18th, and 19th centuries.
The division in British history is quite clear: George II (1727-1760) was the last reigning monarch to lead his troops into battle - on foot, no less, as his horse bolted at the battle of Dettingen - and frequently dismissed the advice of those who begged him not to expose himself to enemy fire. His successor, George III (1760-1820) saw himself as a working politician and bureaucrat, and his vast personal correspondence is filled with the practical details of parliamentary government and diplomacy. George II had grown up expecting to be Elector of Hanover, a title his grandfather had essentially won fighting the Ottomans. George III was a third-generation king working in an increasingly complicated legal and political context.
Arguably what we're seeing here is the changing constitutional role of the monarchy. Monarchy throughout history have - usually - been involved in government and have often been involved in military command. The need to be seen supporting good government has increased over time (in that monarchs have become more exposed to public scrutiny/criticism with the rise of democracy) while the need to be a great general has diminished. Moreover, the need to be one or the other has been forced upon them by the increasing complexity of both fields. That's not to say it hasn't happened, even in the modern era. King Albert I of Belgium personally commanded his nation's army in WW1 and Abdullah II of Jordan is involved in the day-to-day business of his (and commanded Special Forces operations while Crown Prince). Both Albert and Abdullah were/are rulers with considerable personal power, however, offering democratic reform only on their own terms - they didn't/don't really answer to the people in the way that more constitutional monarchs do.
On one final note though, the query about royal families is an important distinction. While reigning monarchs have only rarely taken to the field in the modern era, plenty of royals have fought in living memory. The British royal family has always been happy to risk its "spare heirs" in combat: the future George VI was a Midshipman at the battle of Jutland (1916); Prince Andrew flew helicopters in the Falklands War (1982); Prince Harry served two tours in Afghanistan (2007 & 2012). To hammer home the point above though, all of the above were - or intended to be - career soldiers or sailors. Without a constitutional (political) role, no matter how small it is in practice, they were expected to serve in uniform. There is a gendered aspect to this as well, of course, as princesses are usually expected to be philanthropists instead.