...after I typed some codes and quit the game, when I came back those cheats were gone and I had to retype them to re-unlock them
By default, using a cheat in the game will flag your save as a cheat save. This does the ff:
- disables auto-saves
- puts a little cheat text on your save from the menu
- disables all achievements
- disables all challenges
- warns anyone you co-op with that it will infect their save if they co-op with you and you have a flagged save loaded
The cheats you entered are saved, so you could easily use/toggle them again anytime without entering the code again. So what probably happened here is that you forgot to do a manual save after entering cheats, and your cheats didn't get saved as auto-saves are disabled.
If you're playing on the PC, you can install the Rare Vehicle Cheats (includes Additional Cheats) mod's open version (part of the Gentlemen of Steelport mod compilation), which removes flagging caused by cheats, which will allow auto-saves even if you use cheats.