For MAME specifically, that setting resides in the mame.ini file. However, I've never been able to successfully locate that file in RetroPie or even discover where it could be put manually if need be. Perhaps someone can shed some light on this, but when located you'll want to look for the autosave option and change the 0 to 1.
RetroArch itself also offers this feature, but it will affect the rest of your emulators as well unless 'Configuration Per-Core' is enabled. The 'Per-Core' option is not to be entered into lightly as it can cause it's own set of problems, so it is generally not advised. Either way, that setting can be found at /opt/retropie/configs/all/retroarch.cfg. You'll want to change both savestate_auto_save = "false" and savestate_auto_load = "false" to "true".