Well, since we're all necroposting on here...
If they want money wouldn’t keeping the servers running make them more?
Not sure if you'll see this, but while theoretically, yes, they
could have kept the servers running, there's a couple likely reasons why they shut them down:
1) User traffic vs. required resources. Nintendo stopped production of the 3DS/2DS family of systems around late 2020, and ceased production of WiiU systems in early 2017 - a couple months before the release of the Switch. This is often done when purchases of new hardware decline enough that you'd no longer be at least breaking even if you made more systems (read: more and more systems go unsold, eventually leading to only losses). Combine that with the fact that Nintendo had moved all 1st-party development to Switch by 2019, and 3rd-party development of games on 3DS/WiiU all but ceased entirely, and... Well, let me put it this way: sooner or later, there comes a point when revenue flow decreases enough that older projects have to start pulling resources/revenue from newer projects to continue functioning, and you have to decide whether or not it's worth it to keep those older projects on life support for longer than is necessary.
It should be noted that while greed can play a role in #1, it is not a requirement for #1 to apply. All businesses exist to make money, and even the ones that aren't greedy are often better off minimizing losses where reasonably possible. No point in keeping an old, worn-down machine running if it's costing you more to repair and maintain it than if you just chucked it out and got a new one.
2) Security (Beware - Wall of Text Imminent). This is probably the bigger one here, if we're being entirely honest. Even if you decide to keep a server up indefinitely, even to the point that you burn a massive hole in your pocket doing so, there
will come a point when your server will just no longer be compatible with the most up-to-date security systems and protocols. Once that point is reached, your only true defense against unauthorized attempts to bypass security measures - short of replacing the current servers with entirely new servers and installing new security infrastructure, which can be very expensive and time-consuming depending on the project - is for exploits to remain almost entirely unknown to those with malicious intent.
Funny enough, the Splatoon and Mario Kart WiiU servers went down for months some time before the online shutdown announcement
because one of said exploits was exposed through social media, forcing Nintendo to disable the servers while doing whatever might've still been available to fix the issue. And Nintendo noted afterwards that the servers could go down for good if it happened again (understandable, given those games were using older network infrastructure compared to the Switch versions). Same reason why Dark Souls: Prepare to Die Edition on PC no longer has online play - exploit got leaked all over social media, and Bandai Namco concluded that it would take way too much time and resources to fix the exploit on such an old infrastructure - and while, iirc, it is still possible to do online through modding, since the leaked exploit wasn't fixed for PtDE,
YOU DO THIS AT YOUR OWN RISK.
And it should be noted that #2 isn't limited to just matchmaking servers or discussion forums.
It also applies to online storefronts and everything inside them, INCLUDING payment-processing services. If you can't keep security around payment processing up-to-date, that results in a severe risk of payment information being stolen and leaked should someone happen to breach the now-out-of-date security systems. Which is often why payment processing systems are the first thing to be deactivated after a store closure announcement - to minimize the risk of suffering a disastrous security breach that results in millions of users' payment information being compromised before the storefront is closed.
Put simply, it's very likely Nintendo started seeing the signs of these risks within the last couple years (with the Splatoon/Mario Kart WiiU incident likely being a more glaring sign), and likely determined that it was better to close the eShop/end online services when they did, as it likely let the servers run the longest that could be maintained safely.