Userbase is important, but itself can't explain such an outstanding difference so I tried to think some reasons:
1) First of course is the high quality of games. As much as this point is completely subject and down to preference the fact is Nintendo games are enjoying a pretty good word of mouth. This extends to a larger community and the multiplayer experience and is a major point of selling games such as Splatoon, Smash, Animal Crossing and Mario Kart. Anecdotal evidence: I just bought MK8 today (and I never liked the franchise at all) only because I want to enjoy the multiplayer with friends, and if I get bored I can just sell it for almost the same price lol
2) When Nintendo dominated gaming market (NES and SNES) their IPs branding weren't anywhere near as big as today. NES and SNES were build not only with Mario and Zelda, but with huge third party support that put out many iconic titles. The Nintendo effort cultivating their IPs made their fans loyal and (almost) always ready for a Nintendo console
3) There was a point that some huge franchises have their fandom split into handheld and console platforms, with Pokemon and Animal Crossing fans having a huge presence in handheld market while Zelda and Smash had a major presence in consoles. Now every fan of every IP has the same device, and they can try IPs they never have played before
4) Wii, the only huge console Nintendo had after SNES, didn't appeal traditional gamers interested in traditional gaming experiences. The top 10 of best selling Wii games was filled with party and sports games played with motion controls and whatnot, with only Mario platformers and Smash Bros among ""traditional"" games. Switch user base shares a somewhat similar gaming interest of PS4 and XBOX owners, making them much more prone to buy less famous IPs like Splatoon or Luigi's Mansion. To some extent, same can be said about DS, with many of their owners interested in playing Brain Age of Nintendogs rather than more "hardcore" games.
5) Over saturation of formulaic games in PS4 and XBOX consoles. This must be the most polemic point, but I think public might be tired of playing 10 years of the same style of AAA games Sony and Microsoft put out every years. Nintendo games have a refreshing bright design and focus mostly on gameplay and not graphics or story. While people still in love with Sony/MS games they probably find refreshing to find that Nintendo still making funny Mario 3D platformers. The biggest example I can imagine from this type of concept is Splatoon, it offers a TPS experience totally apart from other games on the market