Answer by taking a quote from the following article:

William Charles Lunalilo was born on January 31, 1835 in a two-story house made of coral brick, an area known as Pohukaina, now part the grounds of the `Iolani Palace in Honolulu. His mother was High Chiefess Miriam Auhea Kekauluohi (later styled as Ka`ahumanu III) and his father was High Chief Charles Kana`ina. He was grandnephew of Kamehameha I by blood and the monarch's stepson by marriage to his mother. His grandmother was Kalakua Kaheiheimalie, sister of Kamehameha's favorite wife, Queen Ka`ahumanu.

King Kamehameha V, the last of the Kamehameha kings, died on December 11, 1872 without naming a successor. Under the Kingdom's 1864 constitution, if the king did not appoint a successor, a new king would be elected by the legislature from the eligible Hawaiian royals still alive. The other candidate was David Kalakaua. Lunalilo was the more popular of the two. His grandfather was Kalaimamahu, a half brother of Kamehameha I and was thus a cousin of King Kamehameha V. His grandmother was Queen Kalakua Kaheiheimalie, sister of Queen Ka`ahumanu. Because of this, many people believed the throne rightly belonged to Lunalilo since the only person more closely related to Kamehameha V, Bernice Pauahi Bishop, made clear she did not want the throne. Another contender was Princess Ruth Ke`elikolani who was a half sister to King Kamehameha V. She was a favorite among the Hawaiian chiefs because of her adhering to the old Hawaiian ways. She was governess of Hawaii and refused to speak English even though she was fluent in it. Her genealogy, however, was too controversial and few people considered her suitable to take the throne. This left Kalakaua and Lunalilo, and of the two, Lunalilo was greatly favored. So great was Lunalilo's popularity that some people believed that Lunalilo could have simply walked into the capital and declared himself king. Lunalilo, however, insisted that the constitution be followed. He issued the following message six days after the death of Kamehameha V:  "Whereas, it is desirable that the wishes of the Hawaiian people be consulted as to a successor to the Throne, therefore, notwithstanding that according to the law of inheritance, I am the rightful heir to the Throne, in order to preserve peace, harmony and good order, I desire to submit the decision of my claim to the voice of the people."  Lunalilo, unlike his more conservative opponent, wanted to amend the constitution to make the government more democratic by removing property qualifications for voting. It was decided that there would be a popular election to give the people a chance to have their voices heard. However, because the constitution gave the legislature the power to decide who would be the next king, the popular election would be unofficial. Lunalilo urged the people of the Kingdom to have their voices heard.  The popular vote was held on January 1, 1873 and Lunalilo won by an overwhelming majority. The week after, the legislature unanimously voted Lunalilo king. It has been speculated that the reason for the unanimous vote was because each legislator was required to sign his name on the back of his ballot, and the legislators were afraid to go against the wishes of the people. Queen Emma later wrote in a letter that hundreds of Hawaiians were ready to tear to pieces anyone who opposed Lunalilo.  At Lunalilo's investiture ceremony, held on January 9, 1873 at Kawaiaha`o Church, the courtyard was filled to capacity and a large crowd watched from outside. Because Lunalilo's popularity was so great, and because he became king through a democratic process, he became known as "The People's King."

Was Lunalilo selected by the legislature?
Lunalilo was the more popular of the two.