I'd like to add that emulators are legal only so long as they don't infringe on copyright. Nintendo was able to get Switch emulators taken down on the basis that they used proprietary data ripped from the console.
Also since I'm a pedant I'll point out that the phrase "ROMs are illegal" is silly because all game cartridges contain ROMs. ROMs distributed on the internet are (typically) copies of the game being distributed illegally. In the context of this question, it's essentially correct. But it's generally 100% legal to dump your own cartridge of the game for personal use and there are many legitimate and ethically consistent reasons for doing so (game preservation, modification, quality of life improvements only emulators offer, etc.). Many video games would be lost to time if not for these preservation efforts. Including some obscure Nintendo games.
And many game companies/publishers are pro-emulation and do not mind so much. Nintendo is just very conservative and prideful, so they maintain a strict anti-emulation stance, despite charging out the ass for their official emulated products.