It's probably more a political gain in clarity than a straight out military gain.
First, let's start out that neither Finland nor Sweden are like Ukraine.
They are long time Western-aligned, rather than Ukraine's unfortunate and not very voluntary membership in what Russia considers its near-abroad club. They are also EU members, which brings in formal mutual defense guarantees, again unlike Ukraine. And they have very little in the way of Russian sympathizers to stir up trouble to justify "assisting ethnic brothers" with. Last, the Nordics generally look out for each other and Norway and Denmark, NATO founding members both, would bring extra pressure to assist them.
So, even in the absence of NATO membership, Russia would be foolish to assume that it could pull a Georgia(South Ossetia) / Moldova(Transnistria) / Ukraine(Crimea) on them and not get the West involved (remember many EU members are also in NATO).
Both countries found it best not to get too lined up with NATO during the Cold War. Finland was treaty-bound not to do so in any case, but their reality is that are rather near Russia and NATO in the 70s and 80s would have been stretched to win a conventional war in Germany/northern Europe, let alone assisting Finland at the end of the Baltic Sea.
Forward to the 90s and it didn't seem necessary to antagonize Russia. Sure, NATO was now dominant, but Russia could be lived alongside with. That was the popular belief in Finland against joining NATO.
Militarily? Both countries have good armies, certainly, but they are also quite unsuitable to attack Russia. Integrating them is easy, using them to "win" against Russia would not be:
Finland: small core army of professionals (15K?) with a massive conscription-based system that can bring it up to 280K on short notice. This is an army geared towards defense in depth, trading space for attacker attrition.
Sweden: 50k professionals-based army, with a small, 4k, conscripts call-up per year.
Again, operating from Finland, which can easily threaten St. Petersburg, means ferrying in troops through the Baltic, past Kaliningrad.
Russia, if it analyzes the military risks logically, will not be thrilled, but is not at any great risk of surprise assault. Then again, the US, with Cuba, shows how antsy a big power can be about having unfriendly neighbors.
So there is some gain, but also a heightened risk of confrontation with Russia along that now front-line 1300km long border. On the other hand, Russia is busy aggressing Ukraine right now so won't have much to be aggressive with in the short term. By the time it's recovered it will be in the same straightjacket attacking those 2 as NATO is in Ukraine: nuclear weapons make bloc-on-bloc direct combat suicidal and NATO's conventional forces can trounce Russia's.
Yes, there is undoubtedly more risk of confrontation on a longer, more sensitive border. But there is also a benefit to bring clarity and stop the temptation for partway adventurism by Russia that could escalate. NATO is on the hook formally, rather than being dragged in accidentally if Russia miscalculates.
For all parties involved, Finland and Sweden will become de-facto untouchable rather than something that needs to be thought about. Both countries' traditionally neutral-ish electorates have come to the conclusion that there is little to be gained by not antagonizing Russia, not because there is nobility in joining a military pact, but because Putin's Russia fundamentally can't be trusted.
p.s. the fact that they are both joining together is not a coincidence. They apparently have had a long standing agreement to take the jump together or not at all.