There are several points in this. First, a king can condemn a person as a mored bemalchus as David hamelech did to Uriah. Note that he was condemned by the navi for abuse of authority hand not for murder
Achav was condemned by the navi and sentenced to death by Hashem, not by bais din. However, this may only be because of a lack of authority by the court.
I think that this is dealt with in Sanhedrin Capter 2 Mishna 1
A king must not judge, and he is not judged; he must not be a witness,
nor be witnessed against.
However the gemara explains this as not applying to Malchus Bais David
"A king must not judge," etc. Said R. Joseph: This is concerning the
kings of Israel; but the kings of the house of David are judged and
judge. As it is written [Jer. xxi. 12]: "O house of David, thus said
the Lord: Exercise justice on every morning." We see that they did
judge; and if they were not to be judged, how could they judge?--as is
said above by Resh Lakish. And what is the reason it is prohibited to
the kings of Israel? Because an unfortunate thing happened as follows:
The slave of King Janai murdered a person; and Simeon b. Cheta'h said
to the sages: Notwithstanding that he is the slave of the king, he
must be tried. They sent to the king: Your slave has killed a man. And
Janai sent his slave to them to be tried. However, they sent to him:
You also must appear before the court. As it is written [Ex. xxi. 29]:
"Warning has been given to its owner"--which means the owner of the ox
must appear at the time the ox is tried. He then came and took a seat.
Said Simeon b. Cheta'h: King Janai, arise, so that the witnesses shall
testify while you stand; yet not for us do you rise, but for Him who
said a word, and the world was created. As it reads [Deut. xix. 17]:
"Stand before the Lord." And the king answered: It must not be as you
say, but as the majority of your colleagues shall decide. Simeon then
turned to his right, but his colleagues cast their eyes upon the floor
without any answer; and the same did his colleagues at his left.
Simeon then exclaimed: You are all troubled in mind (disconcerted)!
May the One who rules minds take revenge upon you. Gabriel came then
and smote them to the floor, that they died. And at that time it was
enacted that a king should neither judge nor be judged, neither be a
witness nor be witnessed against.