There are quite a few ways to do this. The typical NES cartridge is made up of a plastic casing around a 72-pin board. The board is the only part necessary to play the game, but the plastic casing is used in order to protect the board from damage. With a few basic tools, it's a simple task to take apart the plastic casing and switch two boards between cartridges.
Another trick would simply be to obtain a sticker label for another game and place it over the original label, or remove the original label and replace with the new one. That's actually a bit harder, those stickers are almost impossible to remove in one piece and obtaining/making a new one is more difficult than taking apart a cartridge.
Think of it like if you put the entire CD case in a system to play a CD so there was no point taking the CD out, except in this case, somebody did. It's a little harder than that, but not much.