*Could the Pope choose a noble from outside the Empire? Was it always a king elected or could dukes/counts be appointed as well?
/u/ThomasHobbesJr
Good question, and this has been asked before, so with that I have to give you the bad news: nobody knows for sure. The Golden Bull speaks of "the tradition of election since time immemorial" but gave no detail. As far as I know, there are only scattered written records of how things used to be, but insufficient to give a clear picture of the process.
However, we do know some aspects of the election: how it came about, how it evolved, and most importantly how it came to be regulated.
Some background on the practice of elections
The Franks are said to have a tradition of electing their king, which largely means that a gathering was to take place whereby the strongest becomes king and everybody else has to agree to accept this kingship. This carried into the three kingdoms partitioned from the Frankish empire, and in the case of the HRE the most important is the kingship of Germany. The King of the Germans is elected, and he assumes HRE emperorship upon coronation by the Pope. There were HRE emperors who were not a King of the Germans, for example Louis III and Berengar I who were Kings of Italy. Some were able to be both King of Germany and King of Italy, such as the Ottonian emperors.
In the earlier history of the HRE, there was no formal process for elections, nor was there a set of qualifications as of who gets to be present, who gets to be nominated. Simply put, sovereignty was heavily dependent on personal relations, so it was important for important figures to be present in the elections. At the same time, it is believed this practice was not consistent, in the sense that not every king was elected; some were simply appointed as heir to the kingship.
By the early 11th century, the process had become more formalized. In 1024, the two strongest candidates were cousins who didn't belong to any of the great noble houses of the time, so the election was far from a rubber-stamp election. So the process had to be formalized. But not all was well. There were several double elections in the 12th-15th centuries. Rivals simply put up their own elections with their own supporters.
This is the background to the Golden Bull of 1356, it not only set the process but also named the Electors. It was the culmination of a long effort by kings and emperors to secure the throne for their family, and by both secular and ecclesiastical lords to be a great elector and prevent their rivals from becoming one.
Secular electors were somewhat simpler to determine: the strongest ones naturally became great Electors. Yet as the list became fixed and some families became extinct, the remaining Electors refused to add more Electors into their ranks, so the list became smaller. This is also one reason that Austria became NOT an electoral power. The Babenbergs had been electors but their line became extinct and there was no replacement.
Among the ecclesiastical electors, Mainz had secured its place as a great Elector by the 900s, but Cologne refused to accept this and unsurprisingly this helped lead to the schism of double elections. In the end, the seven were named but there were still some changes and conflict. The Elector Palatine Frederick V came under Imperial Ban due to his support of Bohemian rebels at the start of the 30YW and the electoral power was given to the Dukes of Bavaria. And of course, the balance between Protestants and Catholics was very important after the 30YW.
The Golden Bull speaks of "the tradition of election since time immemorial" but sadly as you see the details are fuzzy. Want to know more? Check out Wilson's The Heart of Europe.
Does the Pope play a role?
Yes and no. One important topic you want to read up on is the Investiture Controversy. There is a great post here that you should read. The converse of this is whether the Pope had authority in selecting or declining candidacy for emperorship. The answer is, it evolved over time. Even as late as the 1200s, some Popes were able to wield significant influence on the election, as Pope Innocent III arranged for the election of Otto IV the Welf dynasty the prevent the unification of southern Italy and the HRE. When the relationship fouled, Innocent backed Frederick II who was born in southern Italy and had claims to the HRE. As Frederick became Emperor, he too had to face the wrath of a Pope as he didn't follow through on his earlier promise to lead a crusade. Thus, he was excommunicated. Yet this did not deter him, he went on a crusade and even negotiated the recovery of Jerusalem, all while excommunicated!
As another example, Alfonso X of Castile was elected King of the Romans by a dissident faction in 1256, despite not having territory within the HRE nor having ever set foot there! The claim was all based on his lineage, and in the end it came to naught.
The Golden Bull was an attempt to make sense out of what was mostly tradition, with occasional interference through conflict of power.