For example, what conditions would have led to Mainz becoming an archbishopric while Brandenburg became a margraviate, and Bohemia became a kingdom?
The Holy Roman Empire was a multi-state political entity with a kind of voluntary membership, is the super short answer. While it had an emperor at its head, that emperor was elected by qualified electors within the imperial diet as the "King of the Romans and the Germans" and then was approved by the pope, who would crown the elected king emperor.
Elected kings had certain ancestral qualifications and generally had a relationship to the current emperor, but it wasn't as strictly patrilineal as many other European successions in the medieval and early modern period, though succession from father to son was a possibility. Friedrich III passed the title to his son Maximilian and they ruled as co-emperors until Friedrich's death in 1493, and after Maximilian's death in 1519, the title passed to his grandson Charles V.
Membership was, as I said, somewhat voluntary. Individual holdings or familial estates of powerful nobles could opt in or out - though this seldom happened - and cities sometimes opted in or out. Basel, a city on the Rhine River, switched its membership from the empire to the Swiss Confederation in 1501. This was not done without some controversy, of course, and member-entities leaving the empire was quite rare.
Family politics played a big role in whether certain kingdoms or regions came into the empire in some way or another. Hapsburg holdings were especially prone to being incorporated into the empire based on the dynamics of successorship and strategic marriage. Bohemia became a holding of Ferdinand I in 1526 after the Bohemian king Louis II had been killed, and Ferdinand was a Hapsburg and a powerful noble within the empire - he later became the emperor himself.
The very short answer is that it's very complicated! The empire itself was somewhat decentralized and had various parallel institutions that were meant to balance one another out, and as trends in monarchial politics changed around the empire, so the empire itself changed. As cities and merchants and international trade and banking waxed in power outside the empire, so did those entities gain power within the empire. Free Imperial Cities had representatives in the imperial diet that sat alongside princes and dukes and counts and prelates and bishops and other exalted lords.
You might be interested in Heart of Europe by Peter Wilson, for more. Like I said, it's a vastly complicated question. I hope I helped a bit, though.