Mostly for testing. Developers need shortcuts to reach a late-game area or verify a feature without replaying forty hours, and those debug tools frequently ship by accident because nobody got around to sealing them off — Contra and Sonic the Hedgehog are the classic cases. Other games keep cheats on purpose: Guitar Hero's performance mode strips out the note highway, and Mercenaries slipped Indiana Jones in as a gag. A third category isn't a cheat at all but a glitch, and those can ruin a save file — the Missingno. bug in Pokémon Red and Blue being the notorious example.