I don't know if there is one common answer for why many different countries adopted socialist/welfare state policies following WWII. Instead I will only present my theory about Sweden.
It is first of all important to understand when Sweden started moving towards big government. It is true that the social-democratic party started to rule in 1936 (and would do so until 1976 with the exception of coalition-rule during WWII), but 1936 isn't really the year when it started. Instead I would trace the growth of big government in Sweden to the 1950's. This was the decade when the pension system referendum was held and taxes began to rise. In 1950 the tax rate was about 20% and during the 1990’s it was between 40-50%.
My theory is that this was spurred by a change in opinion among the swedish people. After the WWII, the liberal (in the true meaning of the word) spirit was still strong enough for the liberals to cause the removal of almost all war-time regulations, following a win in the debate called “planhushållningsdebatten.” The only thing that remained was the rent control. But this liberal spirit died out successively and following 1950 the swedish people became much more positive towards taxation. In my bachelor thesis I covered this developement by analyzing letters to the editor in the swedish newspaper Expressen: https://benjaminjuhlin.files.wordpress.com/2016/04/the-geese-that-was-plucked-without-hissing1.pdf (translated) To me it was clear that the Swedes had become more positive towards taxation, and I’m sure that one can have opinions about the ammount of data but until someone presents more and better data I’m still sticking to this idea.
Then we must ask ourselves the question, what caused this change in opinion? I think that much of the answer is possible to find reading Leif Lewin’s doctoral thesis Planhushållningsdebatten. Here Lewin talks about how the ideas of the keynesian revolution was already present in Sweden before Keynes, and how these ideas entered the right due to the influence of Bertil Ohlin. Due to this, there wasn’t really a big ideological movement against taxation and the tax increases, which is covered well in Nils Elvander’s Svensk skattepolitik 1945-1970 En studie i partiers och organisationers funktioner . When it comes to an area such as the socialisation of business the right and the Svenskt Näringsliv put up a tough resistance and practically managed to block the introduction of “Löntagarfonder”. There wasn’t the same resistance at all when it came to the question of taxation and the growth of big government.
There are many theories in this area. The most popular one would maybe be the one about “Statsindividualism” presented by Lars Trägårdh and Henrik Berggren in their Är svensken människa?, where they claim that the there lies a paradox in the mentality of the Swede, in that he is at the same time an individualist (which would explain the liberal history of Sweden) but due to this want to be liberated from his family (which would the explain the growth of big government following WWII). I don’t think it’s this complicated, and believe instead as I’ve argued above that what happend was only that the Swede changed opinion following WWII.
Hope you know that liberal means the opposite of socialist in a European context
/u/benjaminjuhlin makes an important point that I cannot emphasize enough. While the "Scandinavian" or "Nordic: countries share certain cultural traits and, particularly in the latter stages of the Industrial revolution, developed somewhat similar forms of Romanticism that, today, lends Sweden, Denmark, Finland, and Norway (sorry Iceland, you're whole 'nuther bag of putrefied shark) a certain amount of physical (in terms of urban form) continuity, these are separate societies often with stark differences in both government and in their respective relationships with the Continent, Britain, and the broader world.
So, you've received a very well-rounded explanation of the Swedish context - I'll offer another take on Denmark and, particularly, the structure of government that allowed for the well-known Social Democratic/Social Welfare policies of latter years. I should also mention that "socialist" is a difficult term, the founder of Denmark's Social Democratic Party (socialdemokraterne), Louis Pio, was involved in social-internationalist circles, but I'd argue the ideological basis for the Danish Social Democratic policy was developed by Thorvald Stauning who served as the first Social Democratic prime minister in various coalitions from roughly 1920-1940 (with a few short breaks). Stauning was more a politician than an ideologue, but he did espouse a sort of pragmatic, ordered, proto-social welfare system. Denmark then, as it is today, is marked by a healthy collection of political parties, some far more leftist, other more agrarian, others more academic/urbane (Den Radikale Venstre). During Stauning's tenure, there was also the distinct "threat" of fascism, which allowed him and the Social Democrats to function as a center-left, deal-making party. However, in the years after WWII, the Social Democratic platform became somewhat stagnant and the party did not maintain workable relationships with either the left or the right nor did they serve as particularly insightful stewards of the Danish economy which was racked, severely, by the Oil Crises in the 1970s. The prevailing national-level economic notion at that time was one of "equal development" whereby economic growth was to be encouraged with equal resources in Denmark's various districts. While altruistic, it also led to years where the urban areas of Denmark, in particular Copenhagen, were somewhat ignored and stagnated. In turn, the Social Democratic mayor of Copenhagen for parts of the 1960s/1970s was a man by the name of Egon Weidekamp. One of Weidekamp's signature policy platforms was known as totalsanering ("total sanitization"), which was essentially urban renewal (and, frankly, a better name for the policy than "urban renewal). The leftist parties in Copenhagen's government stood in stalwart opposition to totalsanering, despite Weidekamp's castigation that they were acting as "slum romantics". Thus the Social Democrats in the late mid-century had sort of lost the plot and were ushered out of power by Venstre (the "Left", though in Danish politics, the "Left" was, by then, the "right" ideologically...). The new Venstre government, along with other Danish parties, updated the social welfare policies - culminating in a system later known as "flexicurity" - and set about liberalizing the Danish economy. However, they did not hold absolute power so many of the social welfare policies were adapted to a more modern economy rather than scrapped. In turn, the new Schluter government sought to invigorate growth in Copenhagen, seeing the capital as Denmark's window to the modern world - though it's well-regarded for it's quality of life in 2016, Copenhagen was not a particularly admired city until the very end of the 20th century.
However, I said I talk about structure. Now, I'm probably going to rile of few proper historians by bringing up Fukuyama (he is, after-all, more of an economist), but his notion of "high-quality bureaucracy" is particularly apposite to the Danish context. My experience is in urban history, but the policy revolutions in Copenhagen were similar to those at a national level. Denmark officially "liberalized" in 1848 and adopted a liberal constitution a few years later. However, the process of democratization would continue gradually over the course of the next 50 years. Prior to Grundloven (the Constitution), Denmark had been an absolutist monarchy with the seat of power in Copenhagen. In the 15th and 16th centuries, Denmark had a small handful of urban areas and market towns ("købstæder") that were afforded certain privileges in contrast to baronial control of the rural land. Absolutism centered power solidly on Copenhagen and thus, by the 19th century, Copenhagen was larger than any other urban area in Denmark by many orders of magnitude. The old købstæder privilege also severely limited the economic activities of towns, enforced regional monopolies, and essentially banned the concept of "mobile labor" in that many Danes could not, legally, move themselves or their labor. That system was not particularly suited to industrialization, so in 1857 (I believe), Denmark adopted *næringsloven" that relaxed these restrictions and all-but-ended the concept of a købstad.
What does this have to do with social welfare? Well, the industrial period was a time of immense technological, economic, social, and political change. The Danish government authorities were not, at first, capable in any way of managing the necessities of an industrial society. The government of Copenhagen was by, 1848, mostly symbolic and overlapped significantly with royal fiat. Until 1852, Copenhagen was still confined within the old town walls and was increasingly crowded, dank, and grim. The area immediately outside the walls was kept clear from development as a protection against attack. However, artillery improvements soon rendered these walls obsolete and Copenhagen's first government allowed for development beyond the city walls for the first time. Spurred on by over-crowding and ever-increasing migration of rural peasants in Copenhagen's demesne, real estate speculators quickly developed new districts, marked by grim, crowded, and generally miserable conditions.
Copenhagen's government did not have the institutional capacity to manage these developments, but they did develop it. The early lord-mayors were "elected" by a small coterie of wealthy individuals, but the King and this ruling class did establishing unelected "mayors" of certain policy areas (Copenhagen's municipal government still has multiple "mayors", similar to agency heads in the US). These mayors established a professional bureaucracy to manage the affairs of the city with increasing sophistication and efficacy. As the the process of democratization was gradual, political party-based patronage did not develop as such in Denmark at a scale resembling that of the US. Thus, when full-democratization did arrive, there was already an established, well-run, and well-respected bureaucracy in place managing municipal affairs. Rather than supplant that bureaucracy, the Social Democrats - the first major non-conservative party to assume power in Copenhagen - used it to their own advantage by employing the qualities of administrators, but merely changing the "goals" and policies of the bureaucracy. Thus they were able to affect greater change and greater levels of coordination necessary for a social welfare state because the implementing authorities (i.e. the "bureaucracy") were more efficient, more professional, and - this is the important difference with the US - existed largely free from serious patronage (though certain levels did exist).