Many cart-based games used battery-backed SRAM for storing saved game state. The RAM was usually powered by a lithium coin cell that could keep the RAM contents powered for a number of years. Once the battery died, the cartridge lost the ability to store game save data. While the cart was plugged in, the console would power the SRAM so the game would function normally, and even appear to allow a save, but as soon as you removed power, all saves would be lost. The game itself is still stored as permanent ROM, so a dead battery will usually not make the game unplayable, it'll just mean the game can't save stage that will survive between power-ups.
Some carts used soldered versions of lithium cells (they made/make lithium cells with solder lugs permanently welded to the battery) while others, more rarely, used a socket, allowing the battery to be replaced easily after opening the cart. I have personally replaced the soldered cell on a few carts for myself and friends with a socket for a CR2032, the same cell used on most PC motherboards.
At the time these techniques were popular, flash memory was still new enough to be disproportionately expensive compared to SRAM + the battery. Flash also has the disadvantage of being slower than SRAM, so if the game used the SRAM for game logic, flash would have been impractical. Finally, if you think the write endurance on modern flash is bad, the endurance on early flash was even worse, so depending on how often the device wanted to write to NV storage, flash could easily have been worn out whereas SRAM has virtually unlimited write cycles.
Using batteries for nonvolatile memory was done in lots of devices in the 80s and 90s. I had a PDA that used a lithium coin cell for its main RAM, and after that cell died the PDA would "hard reset" each time you powered it off and back on. (I replaced that cell with a socket as well) Other devices that ran on user-replaceable batteries would often include a capacitor that could maintain the RAM contents for a few minutes to allow you to change the batteries without losing data. Others still included the lithium cell along with the user replaceable batteries; the lithium cell basically kicked in whenever the main batteries were low or missing.