I think there are a lot of aspects to this, but first things first, Nintendo has had its share of flops - perhaps more than it's share, and yet they kept going.
Anyway there are 2 sides to this, for gamers and for the corp.
1. They have invested and maintained brand identity for decades now. They've stuck with Mario, Zelda, Metroid and others, and managed to spin-off Pokémon too. Other companies let IPs go dormant or die rather t he an find ways to keep them going.
2.To achieve (1) above Nintendo have been careful to maintain a quality standard for these brands. People know if they buy a Mario game it will be good quality - maybe not their style of game - but the quality is there. Sony and MS haven't managed to maintain the quality across the first parties - and they've been quick to ditch ideas which didn't hit sales first time out.
3. They've avoided over saturation in game mechanics. They produce a lot of Mario branded games, but there's diverse gameplay - platform, kart, RPG, Sports whatever. This has allowed Nintendo to riff on the underlying brand tropes without just putting out the same platformer every year and that avoids fatigue. Again, other companies - specifically Sony and MS didn't do this. halo is an FPS, TLOU 3rd person zombie etc. Their characters are silo'd in their gameplay genres.
4. From Nintendo corporate I think they made an active decision to focus on being a little bit unsung and "quiet" in the gaming space. They haven't let studios and personalities become bigger than the brand itself. Compare to Sony and MS where studio names and even individuals seem to be bigger than the overall corporate identity.
5. Finally, from a games perspective Nintendo make games which have "dense" gameplay. By that I mean that you boot the game and within a few moments you're playing the game with real gameplay. Not watching a lot of CG and voice acted scenes or getting beaten over the head with exposition. Perhaps this is by virtue of weaker hardware, but either way, Nintendo games are about playing the game moment to moment - not long story sequences and slow walking talking. There's a place for that stuff - but too much of it is just boredom inducing.
6. Oh and of course Nintendo make games everyone can understand. Primary colours, simple gameplay mechanics and stories. Yeah that can all seem shallow, but so can the mass of drab, bleak games with obtuse mechanics and stories trying to be edgy at every turn but doing it badly.
I think the danger is that if Sony don't keep going with their first party and exclusives, a world in which Nintendo is the only console gaming company left would swing too far the other way. We need the slow steady mature games to give the brash primary color joyful Nintendo games a counterpoint.
So in a sense Nintendo have been successful because they were the alternative to Sony and whoever else.