Most likely the back fire is coming from the exhaust when the key is turned off and it can be pretty violent. A loud bang sure can scare the heck out of you when it happens!
But why does your lawn mower backfire when you turn off the key?
The reason it does is because there is a solenoid on the bottom of the carburetor that shuts off the supply of fuel when the key is turned off. If this valve fails in the open position, it allows raw fuel to be pulled into the carburetor and the combustion chamber and then it ignites from the heat of the exhaust pipe. Pow!
An easy way to tell if your valve is working is to turn the key to the on position and you should hear a small click from the solenoid valve. You can also hold onto the valve while you turn the key and you will feel it move the solenoid to the open position.
You can remove this fuel solenoid but you must shut off the fuel flow or you may end up having a tank full of fuel on the floor or ground. Hose pinch pliers work well for this.
A test to ensure it is getting 12VDC power to it is also something good to do. Sometimes this valve will get stuck because of the fuel gelling up as the ethanol begins to separate from the gasoline. You can clean it up and then retest it for proper operation.
If you need a professional lawn mower repair shop in your area, visit our Locations page for assistance.