Lots of factors contributed to the Wii U's failure, but really the games are by far the most important thing. Nintendo can, and often does, get most things wrong, but when their games are good enough it doesn't matter. Look, the Switch is underpowered, has a crappy paid online service and got rid of the Virtual Console. It has expensive HD rumble joycons that have no killer app to showcase this technology. Has any of those things kept the Switch from succeeding? Nope. If the games are good enough, then that is all you really need.
More specifically, they didn't make killer apps for their Wii fanbase. The really big franchises on the Wii were: Wii Sports, Wii Fit, 2D Mario, and Mario Kart. The Wii U got no Wii Sports or Wii Fit game. Most 2D Mario fans consider the Wii U game to be disappointing. That really only leaves Mario Kart. Mario Kart, by itself, is not enough to make a console succeed. Both the N64 and Gamecube had good Mario Kart games, but those consoles still got stomped on by Sony. So in the end Nintendo didn't have the killer apps that the Wii audience was looking for.
Also, the most important time for Nintendo to launch a killer app is in the first 12 months. I actually think if Nintendo could have somehow gotten Breath of the Wild, Mario Maker, and Splatoon out in the first 12 months, then the Wii U would have done a lot better. Switch had 4 heavy hitters during its first year: BotW, Mario Kart 8 D, Splatoon 2, and Mario Odyssey. Wii U didn't have any games during it's first 12 months that were as strong as any of these games.
Nintendo consoles succeed when they have a very popular killer app (or apps) that launch early in the consoles lifetime, especially during the first 12 months. The Wii U didn't have that, and that is by far the biggest reason why it failed.