As with most things regarding European royalty you can pretty much blame Charlemagne for this too. At least kind of. To understand why the HRE became an elective monarchy we must also understand a little about the Kingdom of East Francia.
East Francia was one of three kingdoms that were formed in the treaty of Verdun when the Carolingian Empire finally died (the others, somewhat unimaginatively, named Middle and West Francia). With the Carolingian Empire divided three Kings took their thrones (although they basically belonged to the same Carolingian dynasty).
Now, East Francia was given to Louis the German, a man who, just as he had fought a civil war against his brothers, spawned a couple of children who proceded to fight a civil war amongst themselves. To resolve this issue Louis divided his lands into three parts, Bavaria, Saxony and Swabia, this will be important later on (each with a few additional minor territories attached). Now, somewhat unexpectedly and uncharacteristically his three sons decided to actually respect this division upon his death instead of fight another civil war.
Charles the fat (who was given Swabia by Louis the German) eventually inhereted the lands of his two brothers and for a little while East Francia was once again united. For a bried period he also inhereted West Francia, thus reuniting the Carolingian Empire.
So far so good, right? Except, Charles the Fat really only became Emperor of the Carolingian Empire by virtue of out-living his brothers. He was generally seen as weak and inept which was not a good thing in a time when Vikings used the north coast of Europe as their personal playground and every group east of the Rhine routinely came knocking. In 887 he was deposed as emperor and the Carolingian Empire died, again. This time for good.
So who deposed Charles the Fat? His illegitimate Nephew Arnulf of Carinithia of course. Charles basically said "Bad Nephew!" and then asked for a grand estate in Swabia to retire in. Arnulf agreed. Not that it mattered much because Charles died just a few months later and Arnulf was elected King of East Francia. Elected. Arnulf could not simply claim the title, he was not the legitimate heir, therefore he needed the support of the nobles and the legitimacy an election brings.
Now, Arnulf made a bid for the thrones of Italy and Lotharingia which I will not go into further because this post is getting really long as is. He returned home after two inconclusive campaigns in Italy and eventually died.
Arnulf had one legitimate son with a claim to the throne of East Francia, Louis the Child, the last Carolingian ruler of East Francia. Can you guess how this will end yet? No? Okay. Louis the Child was crowned King of East Francia at age 6 or 7, hence the epiteth. The Kingdom was in fact ruled by a group of powerful nobles and clergy. He was a child of poor health and frail constitution and died in 911 at age 17 or 18. Thus ends the eastern line of the Carolingian house.
So now we have a Kingdom that has no ruling dynasty and five very powerful duchies (Franconia, Bavaria, Swabia, Saxony and Lotharingia, see, told you it would matter later on). Rather than turn to the Western line of the Carolingian house these dukes decided to elect one of their own number as King. He was Conrad of Franconia. The first elected Rex Francorum Orientalium. On his deathbed he passed the crown to his rival Henry the Fowler of Saxony who was elected later the same year. His dynasty would hold on to power for about a century but always through election. There we have it, an elective monarchy has been born. Basically because the Carolingian dynasty lacked legitimate heirs.
TL;DR - It was a solution to the lack of legitimate rulers. Being elected basically gives a ruler the legitimacy they need to rule.