A king may neither judge nor be judged. This refers to later kings, but kings of Davidic line may judge and therefore be judged, as Resh Lakish explained “First correct yourself, and then correct others” - only a person who is subject to correction may correct others.
But why may the other kings not judge or be judged? Because of an incident that once occurred. A slave of King Yannai killed a person, and Shimon ben Shetach called King Yannai to court - because of “...and its owner had been warned by witnesses...” – the king, the owner of the slave, has to be in court. Yannai came and sat down. Shimon ben Shetach told him to stand up, but the king said, “I will do as your colleagues will say.” All the members of the Sanhedrin were looking into the ground. Shimon ben Shetach said “You are men of thought! May the Master of thoughts exact retribution from you!” - and they died. The Sages then decreed that a king may neither judge nor be judged.
Art: El Greco - St Louis, King of France