No matter that German lords defied the emperor, they still owed some allegiance to him. He was, de jure, if not de facto, their sovereign, and until the Peace of Westphalia remained their de facto suzerain. Even afterwards, the empire still was subject to the emperor. The title "King of the Germans", incidentally, was invented by the pope (Gregory VII, I think) during the Investiture Contest as a slight, since at the time the emperor used the styles of rex Romanorum and Imperator Augustus Romanorum. When the pope began to call him rex Teutonicorum, it was a) an insult because it implied the emperor had no right to exert temporal rule over Italy, as a Barbarian, and b) correct since, at the time, the emperor as King of the Germans was as much a monarch and king in his Kingdom of Germany as the Kings of France and England were in their own realms. We don't call John Lackland King of the English just because his barons defied him. You will note that titles such as rex Francorum, rex Anglorum, rex Teutonicorum are remnants from their semi-tribal past. I'll grant you that one reason that the Empire never switched to rex Germaniae (as France switched to rex Franciae and England to rex Angliae) might be the strength of the great stem dukes of Germany, but that is really a matter of semantics. The only thing that changed, for example, in the switch from rex Francorum to rex Franciae was the realisation that a) the king of France no longer ruled over the East Frankish realm and b) no one really knew what it was supposed to be anymore. Case in point, the King of Sweden used to be called the King of Goths and Wends until the 1960s.
The Kingdom of Prussia is an entirely different case for two interconnected reasons: a), Brandenburg held the duchy of East Prussia in fief to the king of Poland; i.e. he owed allegiance to it. That dates from the secularisation of the Teutonic Order's Terra Mariana during the Reformation. b), BRANDENBURG was held in fief to the King of the Germans, the emperor, who had granted it unto the House of Hohenzollern in 1415. Since calling himself King of Prussia would have implied diplomatic and legal equality with the King of the Germans (though not the Emperor) that was forbidden to Frederick I, but Prussia lay outside the borders of the Kingdom of Germany, and the Emperor allowed his vassal to hold Prussia as a sovereign state. In other words, Frederick I was the independent king "of" Prussia, but since he also was a vassal of the King of the Germans in the Margraviate of Brandenburg and his other holdings, he had no right to kingship outside the duchy of Prussia. The adoption of "King of Prussia" in 1772 had little to do, legally, with the First Partition of Poland, but rather more with Frederick the Great being kind of a dick. You may note in passing, by the way, that the Archduchy of Austria always remained an Archduchy instead of being elevated to a kingdom, though it was held by the Emperor, because it was legally part of the Austrian Reichskreis and thus of the Kingdom of Germany (held by the emperor).