In the times of the Bais Hamikdash, were judges appointed by the king, or were they elected by the people? And was the system different based on which size court (i.e., courts comprised of 3, 23, or 71 judges)?
From Rambam, Hilchos Sanhedrin Ch. 2 (Chabad.org) it appears that, for the most part, the appointment of judges was the responsibility of the Supreme Sanhedrin:
Our Sages relate: From the Supreme Sanhedrin, they would send emissaries throughout the entire land of Israel to seek out judges. Whenever they found a person who was wise, sin-fearing, humble, modest, with a good reputation, and beloved by people at large, they have him appointed as a judge in his own city. From there, they promote him to the court which holds sessions at the entrance to the Temple Mount. From there, he is promoted to the court which holds sessions at the entrance to the Temple Courtyard, and from there, to the Supreme Sanhedrin.
It seems that judges could also be appointed by kings, and afterward, exilarchs. Ch.3
Whenever a Sanhedrin, a king, or an exilarch appoints a judge who is not fitting and/or is not learned in the wisdom of the Torah and is not suitable to be a judge....
Chapter 5 (Halacha 1) implies that the king's power of appointment was limited to courts of 3:
A minor Sanhedrin [of 23 judges] for every tribe and every city may be appointed only by the High Court of 71 judges.
According to the Jewish Virtual Library:
Judges received their authority from their immediate predecessors who "laid their hands" upon them, a process known as "semicha." The president of the Great Sanhedrin was the authority who conferred judicial powers on graduating judges in a formal procedure before a court of three. Judges were, however, also appointed by kings, a power which appears to have eventually devolved with the rule of Babylonia.