You are confusing 2 events. It's true that the USSR almost completely failed their first invasion of Finland. Though for reasons that are much much more complex than simple terrain imo.
But after barbarossa, Finland then seized the opportunity to regain it's earlier losses and attacked the USSR, this time with german help.
That didn't turn out well for the Finnish, and their situation was extremely dire by the end of WW2. Which is why they sued for peace in secret. The USSR could have taken the entirety of Finland at that point, and in fact the finnish government basically evacuated the capital. Why didn't stalin go for it? I guess we can't really know but from the wiki article:
"Stalin's desire to crush Hitler quickly and decisively without distraction from the Finnish sideshow" concluded the war.
Not only that, but for decades after the war, the Finnish communists (puppets to the kremlin) became extremely powerful politically. Finland was forced to hold trials against its own army, and for a time was completely subservient to the soviets. So if they really wanted to take over the entirety of Finland in 1940, I don't see why they wouldn't have done it in 1945.