So, let's say your feudal overlord is rebelling against the king. Who do you owe your allegiance to, the lord, or the king? It's best to fight for the one who's going to win, obviously, but what would the lawful decision be?
In practice, throughout most of Western Europe, the nobility rapidly descended into just that subset of tenants who owed allegiance directly to the monarch - the tenants-in-chief.
Likewise, only those tenants-in-chief were generally liable for treason - those below the nobility being both too valuable and too numerous to hold accountable for the acts of their liege-lords. Provided they subsequently swore fealty to whomever the monarch replaced their treasonous former lord with, all was in general forgiven.
The primary exception to this was in the Holy Roman Empire, where the original stem duchies splintered into far more numerous imperial princes holding Landhoheit - sovereignty - within their own territory and entitled to inter-marry with reigning dynasties.
As Matthew Mantrell said:
-"What is the first duty of a knight?"
-"To his lord, ... then to his lord's lady."
-"And what of the king?"
-"A knight is loyal to the king, of course - but that loyalty goes up through the chain of vassal and suzerain to his lord, and his lord's lord, on up to the king."
-"And if the king wars with the knight's lord?"
-"Then the knight must side with the right. But if his lord is wrong, and the king is right, the knight must go to his lord and formally remove himself from the lord's service. After that, if there's anything left of him, he can go offer his services to the king."