This is what is most likely happening:
Light guns are recognized by Windows as mice. When you have more than one mouse connected, or a mouse and a light gun, Windows assigns each one its own number.
When you first got your light gun, Windows was already running and you had your normal mouse plugged in. Windows assigned your normal mouse as mouse one. When you plugged in your light gun, since windows recognized it as a mouse, it was assigned as mouse 2. Then you went to your mame game and in the game controls setup, you told your game to use light gun 2/mouse 2
When your light gun is plugged in when the computer is off and Windows boots, Windows is assigning your light gun as mouse one, and your mouse gets assigned as mouse 2. Therefore your game settings aren't matching Windows mouse assignments anymore.
After performing a reboot with the light gun already connected, run your game and hit the TAB key. Go to INPUT THIS GAME and reassign your light gun X and Y.
Your gun should then work all the time as long as you always keep it plugged in. If you ever boot with the gun unplugged, you'll have to go back into the game controls settings.