I believe the reason this happens is because the way windows assigns ID's to usb emulated devices is funky. So if you are unplugging and replugging any usb devices it can screw with the USB id's and then mame freaks out and defaults the list or blanks it.
What i do to overcome this is to never, ever unplug anything, and then once I setup my guns/controllers I make the default.cfg read-only. You can do the same to the individual .cfg files that are generated for the games, if you have specific this-game-only controller configs. So for example I play point blank the most, so I can right click ptblank.cfg and make it read only and then nothing can change that controller config. You'll have to uncheck read only in properties to get mame to be able to edit it again though if your ID's change and you need to remap!
I've used the program above, but frankly im not sure if it works or not. Something to do with directinput vs rawinput (i think?), so it depends on the device type whether or not it is able to actually map them correctly on boot.