Among the rules that are unique to a Jewish king are laws that relate to the king’s place in the courthouse. According to the Mishna (18a), a king can neither act as a judge nor can he be judged, similarly he cannot testify nor can others testify against him.
The Gemara on today’s daf clarifies that the limitation on being judged does not apply to Jewish kings from the Davidic monarchy; it only applies to other kings. The fact that kings from King David’s family do judge is based on a clear passage in Sefer Yirmiyahu (21:12) that charges those kings with meting out justice and protecting the oppressed in the courtroom.
The Gemara relates further that the law limiting a Jewish king who is not from the House of King David from being judged or acting as a judge is based on a story that took place with King Yannai. The Gemara relates that once a slave belonging to King Yannai killed someone and was brought to trial. Shimon ben Shataḥ, the presiding judge, commanded King Yannai to attend, since it was his property that was on trial. Shimon ben Shataḥ insisted that King Yannai stand in the courtroom, but King Yannai agreed to do so only if the other judges agreed to make him do so. No one aside from Shimon ben Shataḥ was willing to make such a demand of King Yannai, leading Shimon ben Shataḥ to threaten them with punishment, which, according to the Gemara, brought the angel Gavriel down to smite them.
King Yannai, following in the footsteps of his father, John Hyrcanus, was a supporter of the Sadducees who was always at odds with the Rabbinic Sages. After his losses in battle, and the king – who also acted as the High Priest – refused to perform the Sukkot water libation in the Temple according to the Rabbinic interpretation, the tension led to civil war in which many of the Sages were killed. Some fled the Land of Israel, while others – including his brother-in-law, Shimon ben Shataḥ – went into hiding.