Swedish foreign policy during the first half of World War 2 is seemingly dictated by the idea of national survival. They sent volunteers and materiel to Finland to help avoid the USSR from bordering Sweden (as well as to avoid instability as a result of national popular opinions being in favor of helping Finland). They gave multiple concessions to Germany as to avoid a conflict with the country that basically encircled all of Sweden.
In 1943 however, a policy shift occurred which started with the Termination of the troop transit treaty Sweden had with Germany. As the war progressed and Germany's situation became more and more dire, not only did Sweden undo a lot of the concessions made to Germany, they also made more overtures to the Western allies with trade agreements, the training of Danish and Norwegian 'Police Troops', and allowing US use of Swedish Airbases.
Why did Sweden choose this route instead of only ending their concessions and agreements with Germany, and returning to stricter neutrality?
Sweden had by ww2 a long tradition of being free of allegiance, aiming towards neutrality in any war. When war broke out, Sweden declared itself neutral. However, this neutrality was not all there was to it. There were an ongoing debate during the interwar years on neutrality and how Sweden should aproach it.
After ww1, Sweden found itself in the enviable position of not only having come through the war largely unscathed but also in a new and very favourable strategic position. Russia, Sweden's arch enemy had collapsed and had descended into a civil war between the whites and the reds. Germany laid defeated and had severe restrictions eneacted upon her armed forces and navy. And to add to that, a string of new smaller states had emerged on the other side of the Baltic Sea. Suddenly Sweden's navy was the strongest in the Baltic Sea and two grand powers that had bordered it laid in ruins and much of the Imperial Russian had become the territory of small and friendly nations.
This combined with the creation of the League of Nations brought hope in Sweden that future conflicts would be resolved through that institution rather than through war and Sweden acted like it - in 1918 the inhabitants of the Åland islands had voted to join Sweden and Swedish forces had briefly occupied the islands before being told sternly by the Germans to leave. Sweden and Finland agreed to bring the issue of the Åland islands to thr League of Nations, which eventually resolved the matter in Finland's favour, although with a far-reaching autonomy for the Ålanders which included a continued ban on fortifications ont he islands, exception for the Ålanders from Finnish conscription and guarantees of the autonomous status and the Swedish language on the islands.
In this situation, Sweden decided to make extensive cuts to its armed forces in the 1925 defence decision. The army went from 6 line and 6 reserve divisions and 1 cavalry division with two brigades at Gotland and Boden to 4 line divisions, 1 cavalry brigade, 1 infantry brigade and the two brigades at Boden and Gotland. Conscription was reduced from 360 to 240 days, and the full 240 rarely served. Not all men of each year's class was called up and winter exercises became scarce.
The wake of this great reduction of Sweden's armed forces, a debate started within the armed forces and related political fields (mainly defence and budget, but also foreign politics), which essentially divided it into two camps - the traditionalists who were in favour of a stronger defence and had leaned conservative politically and were in general German-friendly and the antingen-eller (either-or) faction who were prepared to work with liberals and social democrats and who argued that Sweden needed to either have a defence strong enough to deter a grand power (making the enemy think that while he could take Sweden, it would not be worth the effort) or that Sweden needed to abandon neutrality and form alliances or defence treaties with other countries to come to their aid (and the other way around) should either experience an attack in line with the rules of the League of Nations. This faction was also more western-oriented than the traditionalists. Of course this primarily focused on helping Finland against Russia, but some kind of defence pact with Denmark and Norway was also on the table. Either-or would eventually come to mean as much its original intention as "either we defend Sweden in Karelia, or at Stockholm's outskirts".
In 1938, negotiators from Sweden and Finland discussed a mutual defence of the Åland islands (as they were still a demilitarised zone void of fortifications in peacetime) in case of war and a mutual defence treaty. There were severe problems with the negotiations though - Finland was going through some issues regarding the status of the Finnish and Swedish languages at the time, and there were a core of hardline Finnish nationalists in the Finnish army who had little regard for Sweden and what they regarded as a lax and lazy attitude to the threat of the Soviet Union and communism at large. Mannerheim, commander in chief of the Finnish armed forces opted to send Colonel Airo to head the Finnish delegation. Airo was a close associate of Mannerheim, chief of the operative department of the Finnish general staff and secretary of the Finnish defence council and had studied at Saint-Cyr. Few had the knowledge Airo had of the Finnish defence situation. He was also a hardline Finnish nationalist and Mannerheim probably chose him to head the delegation, since a treaty or agreement made by Airo would then be acceptable to the other nationalists in the Finnish armed forces. However, Airo refused to speak Swedish (despite being fluent) and negotiations had to be conducted in French. Airo probably thought that the Swedish delegation would never get the approval of more isolationist politicians and that the negotiations were a waste of time, and they were conducted in an icy atmosphere where Airo piled Finnish demands on top of each other and replied "We're here to discuss what Sweden can do for Finland, not what Finland can do for Sweden!" when asked what Finland could offer in return.
The failure of the negotiation was a severe blow to the either-or faction in Swedish defence policy and foreign politics. The result was that Olof Thörnell, a staunch traditionalist was named ÖB (supreme commander) of the Swedish armed forces and that Rickard Sandler, a staunch either-or supporter and in favour of a Nordic defence cooperation was replaced as Minister of Foreign affairs by Christian Günther, who was a non-political civil servant but also known as German-friendly and in favour of neutrality rather than intervention - both happened in December 1939 when Sweden formed a government of national unity (samlingsregeringen) with all parties in the parliament except the communists as a response to the Soviet attack on Finland.
As you can see, there were an on-going debate on Swedish defence policy, alignement and neutrality versus interventionism, and Nordic defence cooperation before ww2, and the traditionalists and strict neutralists and German-friendly had the upper hand at the time. Sweden was dependent on imports from Germany and German-controlled Poland - mainly coal and coke, but also fertiliser, engine grease, steel (Sweden did not have the steel mills to supply its own need to steel until 1943 and exported iron ore and imported steel), animal fodder and artificial rubber.
This dependence on German trade worsened significantly after Germany took Denmark and Norway and started gaining a signficant influence in Finland. Suddenly Sweden, which had only a few years previously enjoyed a very sound strategic situation, was surrounded by hostile or semi-hostile grand powers. While Sweden had started re-armament in earnest in 1936, it was not until the Winter War that it went into over-drive and by then very few other countries were selling arms and the Swedish industry had problems delivering all what the Swedish armed forces needed. Italy was willing to sell planes, destroyers and MTBs, but demanded pay through the nose in strategic raw materils and hard currency - this deal also led to the so-called destroyer affair in June 1940, where the Royal Navy seized the 4 Swedish destroyers en route from Italy, fearing that they would end up in German hands. Despite the British releasing the ships to sail onwards to Sweden only a few days later, this did sour the Swedo-British relations during that time. Likewise, the US impounded 60 J 9 (Seversky P-35), 114 J 10 (Vultee P-66) and 50 B 6 (Republic 2PA). Sweden bought arms from Germany (part of it was loot from Austria and Poland, which had used Bofors designs) and negotiated a treaty with both the British and the Germans to be allowed to pass a certain number of ships through the British blockade and German minefields of the North Sea - however, this amounted only to 15% of Sweden's pre-war overseas trade.
Continued below.