1) Pre-empt false information
Russian use of disinformation
The Russian government is the most probable aggressor that Sweden may be considering at the moment, and the Russians have spread disinformation/lies extensively in recent years against Ukraine (Reuters, Washington Post, Univ. of Washington, FPRI), during their recent military invasions of Crimea and Dombass, and even against Sweden in diplomatic matters (Washington Post). It seems highly likely that a Russian invasion of Sweden would involve deception of some sort.
The development of technology has made it possible to fake the statements of leaders. In the past, militaries worried about voice impersonators faking orders from the president, but now real-time facial reenactment technology makes it likely that a government can produce highly realistic-looking computer-generated video of a recognizable public figure such as a president saying anything the video maker would desire, complete with emotional expressions. A general could be videoconferencing with their president, asking them questions about their decision, and not be able to discern whether they are videoconferencing with a person or a computer-generated image.
If an aggressor can convince the general public in the nation being invaded that their army has surrendered, then the public will put up less resistance.
2) Deter invasion by increasing occupation costs
A hostile populace with significant resistance to occupation is very difficult to govern. Thus, this declaration is an attempt to increase the nation's civilian-based defense, and make occupation more costly and therefore less desirable for potential aggressors.
3) Boost morale
Discussing fighting no matter what takes the battle out of a pragmatic mode of thought and puts it into a different motivational framework. This is part of a rhetorical strategy which declares that it is valiant, honorable, and right to die fighting rather than surrender.
In an era where Russia has been annexing territory, some might ask: "Are we next?" Refusing the possibility of surrender makes the answer a resounding "No and never" rather than a more measured "We'll make the best choices we can given our circumstances."
4) Avoid the authority problem of surrenders
The problem of who has the proper authority to surrender is a difficult one. In times of war, the military situation can change quickly and accurate information might be difficult to communicate. Leaders may be killed or unable to be communicated with while they are in hiding. Other leaders may be kidnapped, coerced, or bought.
In this situation, who should get the authority to declare a surrender, and under what circumstances is this surrender valid? This is difficult logistical problem, and it's conceivable that is easier to simply forbid surrender than solve this conundrum.
5) High costs of surrender
The rest of these answers are better explanations because they explain why this policy would be determined in advance and publicly declared. This policy seems to prohibit later policy changes to adapt to different circumstances.
However, there may be circumstances where the projected costs of surrender are believed to be unacceptably high. For example, the opponent state may limit individual freedoms or perform practices which the culture in question finds unconscionable or abominable.
These answers are in order of realistic significance, with #1 being far and above the others in my opinion.