You don't give your engine model number but I am suspecting that the plastic cap on the fuel solenoid on the bottom of the carb is coming loose and shutting off fuel flow and when you turn the key off the plunger released and pushed the cap back on the end of the plunger. Remove the fuel solenoid from the carb and pull on the plastic tip and see if it comes off. If it does you can epoxy it back on or throw it away if you don't mind some backfires on shutoff.