In the early days of game development, few knew how to make a balanced game, and of those that did, didn't always have time to meet their launch window and make it balanced; most games were in the category of Nintendo Hard (warning: TV Tropes). Programming was also time-consuming, so it was often easier to program a cheat code in for testing, and it didn't always get taken back out again. The same is often true for other kinds of assets as well; many times assets like sprites, animations, music, and code are left-over on the cartridge, disc, or inside the game files. These are left-over artifacts from not having enough time to do everything a developer wanted to do.
The first major blows to cheat codes were the introduction of difficulty options and improved developer tools. Developer tools allowed for faster build times, more advanced programming languages, etc. Cheat codes were less necessary, because developers could quickly change memory and code. Difficulty options basically split gamers into two groups. The hardcore gamers that thought the challenges were rewarding and there shouldn't be an easy mode, and the casual gamers that thought a game should be accessible to (almost) everyone.
If a hardcore gamer-programmer had to introduce an easy mode for marketing reasons, it was usually in a mocking manner, like Doom Guy's baby pacifier face on "I'm Too Young To Die" difficulty. Much later, more accessible games would introduce a casual player's quick mode, called "Story Mode", with limited or no combat and no challenge whatsoever. This is the mode you're likely thinking off when you talk about a game you want to just enjoy quickly. At any rate, almost any game with difficulty modes was already easy and fast enough for a casual player, so introducing cheat codes wasn't necessary. If a game had codes, they were easter eggs or cosmetic differences.
Eventually, DLC became readily available. At first, it was just cosmetics or maybe a decent starting boost to the game. After a while, games were just designed to require absurd amounts of grinding that was fixed by paying some price for a triple-experience DLC. These games were designed to frustrate players, so no cheat codes here. They then moved on from this to energy meters and progress meters that ran in realtime, which you could advance faster by purchasing in-game premium currency, known as microtransactions. They also started adding loot boxes and battle passes for extra rewards that would move you along faster, and other pay-to-win mechanics. Cheat codes are antithetical to the concept of pay-to-win.
Also, keep in mind that many modern games are also live services. That means that you can play with other players, and you'll see their cool items and abilities, and want them for yourself, so they'll offer loot boxes and battle passes and everything else to entice you to spin money so you can be powerful and/or cool like that one person you saw.
In addition, a lot of game engines had "mod" capability. Anyone with skill could make a game do pretty much whatever they wanted to. You no longer had to cheat, just install a file to customize the game the way you want to. Any game with this system was also unlikely to have any built-in cheats, since the players could already customize the game however they wanted to. It simply didn't make sense to include a cheat mode. Also, games started introducing multiple game modes, like Minecraft's Creative Mode, where a player could build without fear of dying.
Most modern games don't have cheat codes (except maybe cosmetics) because (a) they would not be used by the target audience (e.g. hardcore gamers), (b) the game already has a ton of accessibility features and difficulty levels, (c) the game is intentionally grindy to extract dollars from your wallet, or (d) the game is nearly infinitely customizable anyways, so players can completely customize their experience.
As far as your specific idea goes, there are few cheat codes in modern games out there because there isn't any incentive to have them in a game in the first place. Hardcore games are not designed for casual players. Games with run long times don't really have a way to shorten the story they want to tell without cutting out critical plot elements, though many will let you skip some or most cutscenes, but that tends to leave first-time players confused. Casual games typically already have more than enough accessibility features without needing hidden codes. Microtransaction games intentionally stretch out the game time in hope of earning more dollars.
Also, cheat codes used to be hard to find, but today, you can find virtually any cheat code in seconds on Google, so that takes a lot of the fun out of it for many people. There is a small niche market with people like me that like discovering secrets and bugs, but even I would typically rather just have a menu option than have to find the code somewhere on the Internet just to play a game.