I'll take a stab at answering this question.
First off, it's important to note that historians have increasingly come to see the "Protestant Reformation" as part of a wider movement of religious reform and renewal. Across Europe and the Mediterranean there was an efflorescence of new religious ideas and practices, accompanied by a drive towards reforming religious institutions and enforcing religious unity. Why this occurred is a matter of some debate, but some of the likely factors include the expansion of state power, the development of the printing press, and simply the experience of major events like the conquests of Constantinople by the Ottoman Empire and of Granada by Christian Spain, not to mention the discovery of a “new world.”
I mention all of that because I want to stress that kingdoms did not simply “remain” Catholic. Rulers, and people of all walks of life really, were forced to respond to this reality. In some places like Spain, Protestant ideas did not really catch on, but the drive towards religious purity and expansion was expressed in other ways, such as in new religious orders like the Jesuits, improved education, particularly for the clergy, establishing missions abroad, and conflict with Islamic powers.
Why did other kingdoms choose Protestantism? While some have sought to make broad generalizations connecting the rise of the middle class to Protestantism, that theory doesn’t hold up to scrutiny. Protestantism certainly appealed to many merchants and artisans and others who might fit the definition of “middle class,” but many of that class also remained Catholic. Even if the “middle class” did turn to Protestantism in the short-term, it was ultimately the decision of the government to adopt Protestantism as its state religion that ensured its success. This generally came about in one of two ways: a top-down reformation imposed by a Protestant ruler, or a revolt overthrowing the Catholic regime and replacing it with a Protestant one.
The most famous example of the top-down style of Reformation is probably England. It also highlights the difficulty in answering this type of question. I won't go into the whole story of Henry VIII and Catherine of Aragon here. The details are readily available pretty much everywhere but this case highlights the mix of religious and political reasoning that rulers made when deciding to break with Roman Catholicism. Did Henry VIII simply break with Rome because it allowed him to divorce Catherine of Aragon, or was it a consequence of his belief that supremacy of secular rulers in both secular and ecclesiastical matters? It is impossible for historians to truly know the motivations of historical actors. What is clear is that Henry certainly had something to gain through breaking with Rome and in so doing, he allowed for the spread of Protestant ideas in his kingdom, even if at the time of England’s separation from Roman Catholicism in 1534, the country had not been particularly a centre for Protestant agitation. This sort of top-down approach also played out in the German territories and was enshrined in the 1555 Treaty of Augsburg which guaranteed rulers the right to choose either Lutheran or Roman Catholic church order in their domains. Thus, a state could simply become Protestant as a result of the religious views of the ruler.
To leave it at that would massively oversimplify the situation following the Protestant Reformation. While rulers had a great deal of power to impose their will in religious matters, that power was not absolute. Therefore, Protestantism could also take hold when it allied with a popular resistance movement. Such was the case in the Low Countries. The Low Countries were ruled by the same branch of the Habsburgs that ruled Spain. When Philip II came to power, he ramped up efforts to stamp out heresy in the Low Countries. This agitated many Netherlandish elites, not necessarily because they loved heresy, but moreso because they resented the way Philip's agents disregarded local privileges. Iconoclastic riots caused Philip to send the Duke of Alba with an army to restore order. His harsh rule, including the execution of two of the senior noblemen in the country (the Counts of Egmont and Horn), pacified the country in the short term but led to a resistance coalescing around the Reformed Protestants, who provided recruits and funds to the resistance led by William of Orange. Eventually, Alba's policies and the mutiny of unpaid soldiers caused a general revolt across the Low Countries. The conflict dragged on until 1648, but the result was the independence of the northern Netherlands as a Protestant republic. However, Spanish victories and the alienation of the Catholic majority in the southern Netherlands (modern Belgium) ensured that it remained under Spanish rule. A similar situation occurred in Sweden where resistance led by Gustav Vasa against Danish rule saw the cause of Swedish independence linked to Lutheran reform.
Ultimately then, Protestantism took hold where it did because it suited the religious and political context of those regions. It was often most successful when it allied itself with other political agendas. That is not to say that proponents of Protestantism adopted it for purely political gain. The religious and political cannot be easily separated in this period. Indeed, Luther's message was a political as well as spiritual one. He addressed political elites both publicly, in Address to the Christian Nobility of The German Nation (1520) for example, and privately through a massive network of correspondence. Little surprise then that a religious reform movement born out of the religious and political context of the German territories would appeal to political leaders in northern Europe. Similarly, southern Europe often had its own brands of religious reformers such as Ignatius Loyola whose approach resonated more in Spain and Italy.
I hope that answers your question at least partially. However, like I mentioned, it is a difficult question to answer fully. Please feel free to ask for additional clarification and I will try to provide it!