Nintendo does whatever they think is in the best financial interest of the company. I predict we have one or more things going on here:
1) Wii U + 3DS software sales were so low that it was costing them more money to keep their digital stores going for much longer.
2) Wii U + 3DS software sales were so good that it was causing an opportunity cost issue because too many gamers weren't buying into the Switch ecosystem yet due to being happy with what Wii U /3ds offered and weren't getting as much money as they could if they shut those two down to pressure people to upgrade to a Switch.
3) They plan to release many of the Wii U/3ds available games on either Switch eshop or down the line on NSO or NSO+.