(And I took a look at the first of those, but it looked far more complicated and involved than in just reprogramming the gamepad every time I plug it in.)
I would call the lost settings a bug. You might notice that the first time you run MAME with the gamepad disconnected, your modified (grey) settings are still there, minus the missing 'joy' entries, but the next time you run (with or without the gamepad) the settings are all white again. This is because MAME encounters an unhandled exception during its exit routines while it's trying to figure out how to rewrite the changed configuration. That results in the default.cfg (or
gamename.cfg) being truncated to 0 bytes. When MAME starts the next time, it recreates the cfg file with the default (nothing specifically redefined) configuration.
Fortunately, for this case, you don't need to reprogram your settings each time, and you don't need the other utilities unless you have multiple devices that move around on you.
Just connect your gamepad, start a game, reconfigure the controls under General, exit MAME, and copy cfg\default.cfg to ctrlr\gamepad.cfg
Then, when you start MAME, add
-ctrlr gamepad to your command line (or change the
ctrlr entry in your mame.ini to
ctrlr gamepad) Since MAME doesn't modify the ctrlr files, the settings don't get lost even if the gamepad is disconnected.
Note that there could be things in the default.cfg that wouldn't belong in a ctrlr config, but since your default.cfg has been getting wiped out anyway, that's not going to bother you. Also, keep in mind that any game's controls which aren't on the General menu will have to be manually copied from the game's cfg file into the ctrlr file. (You can ask for help with that if you run into those games)