And even when a member of the House of Habsburg wasn't elected (Charles VII), he was descended from a Habsburg dozens of different ways, and immediately after his death, it went right back to the new House of Habsburg-Lorraine, who were just a matrilineal extension of the old House of Habsburg.
Mainly by being good chums with the electors and, since Ferdinand I.'s permanent acquisition of the crown and thus electorate of Bohemia in 1526, direct influence in the worldly curia. Also, lots of bribes at times.
When Maximilian I. died in 1519 no German candidate came forth so the election was between Francis I of France, a de Valois and obviously unfavorable candidate, and Charles, a Habsburg by genealogy but in his main role as king of Spain even more of an outsider. So the election turned into more of a bidding war, which Charles eventually won, not the least due to the profitable Spanish colonies.
If we're talking about the later Holy Roman Empire under the Habsburgs there is a lot of politics involved.
When the Emperor died the Bishop-elector of Mainz had to call together all the electors within 30 days. Although that didn't necessarily mean they had to make a decision right away; when Ferdinand IV. died in 1654 it led to one of the longest interregnums of one year before the curia could finally be swayed to chose his younger brother Leopold over the other and initially more influential candidates from France and Bavaria.
Of course, the Emperor could and often would use his influence to support a future candidate, obviously mostly his son, before his time was up. Sometimes the electors would even chose a successor while the current emperor was still alive, such as Joseph II., who was elected and crowned römisch-deutscher König in 1764, a bit over a year before the death of his father, Francis I.
If the emperor died without having successfully gotten his heir elected, the position was theoretically open for anyone who thought he had a chance (I am not sure on what restrictions there were, but candidacy certainly was not limited to one or more families like /u/Athena_Nikephoros said), although practically it was obviously much easier if you already were an elector as it meant you had one sure vote and a lot of connections. It was also preferable if a candidate held considerable political and military power to keep all those quarreling little states in check without having to call up the Reichsarmee at every occasion.
In the end, it often still came down to who could promise the best concessions, monetary, political or otherwise, to the curia.
Obviously, the Archdukes of Austria held many of those trump cards. As kings of Bohemia they had a regular position and vote in the elector curia, as archdukes of Austria they had an elevated status akin to that of the electors plus leadership of the ecclesiastical bench of the Reichsfürstenrat in the Imperial Diet (although being a secular country, so not led by a bishop or other clerical figure) and with the combination of their HRE lands plus the kingdom of Hungary they could levy lots of troops on their own.
As for Charles VII., he was a Bavarian Wittelsbach who jumped at the chance to seize power. He might have been related to the Habsburg dynasty through political marriages but then so were most of the imperial houses. His only close connection was his great-grandmother, Maria Anna von Österreich, while he was far more directly related, through his mother, to the Polish royal Sobieski dynasty so if anything was more Polish than Habsburg. He was a disruption of the Habsburg hegemony on the Holy Roman throne, if only for three years, there's no way around it.
The election of the Holy Roman Emperor was not like a presidential election today. Only people within the Imperial family could become Emperor. The nobility of the various duchies and principalities could really only choose the best candidate from the Habsburg line.