In general a Game Genie was designed to sit between the console and the cartridge and when the console asked the cartridge for data the game genie could secretly change it before passing it back to the console.
So for example you have a game where you start with 3 lives. That number 3 exists somewhere in the data or code on the cartridge.
Let’s assume the number 3 is stored at the 5000th byte of the cartridge’s data bank. On the Game Genie you’d enter a code like “50 00 99”. This would tell the genie that every time the console tried to load the number from address 5000 to send back a value of 99 instead of what was really there. Now when a new game starts you have 99 lives because that’s the number the console received.
While that code is obvious in its meaning the genie usually used scrambled codes in a known way, so for example you might actually enter the code “90 05 09” and it would get unscrambled into the more meaningful code.
Different consoles had different ways of working. On the NES the cartridge was linked directly into the CPU bus in such a way that it could control all memory, not just the cartridges (this allowed NES cartridges to enhance the original hardware, not just provide game data) by routing any memory access through the cartridge pins first. This means that the cartridge could even override the data in the consoles built in ram.
So Game Genie codes for the NES might do things like “hold” a byte. What this means is that it essentially kept a value in RAM locked – attempts to change it wouldn’t work. So you have a place in ram where health was stored and when health reached 0 you are supposed to die. The game genie could just hold that value at 99 and now you are invincible.