I am assuming it backfires out the exhaust pipe and not the carburetor.
The exhaust manifold and exhaust system are hot and raw fuel is getting into it and exploding. After the ignition is shut off the engine will keep turning over enough to pump air/fuel mixture into the exhaust system.
Another possibility is that the ignition is somehow happening with an open valve which ignites any unburned fuel in the exhaust system. But this is very unlikely.
There are several things you can do. You can idle the car for a while to cool down the exhaust system. Or you can turn off the gasoline and wait until the engine stops because it ran out of fuel, and then turn off the ignition.
Make sure the timing is correct and the air/fuel ratio is correct. There have been many things written about this here on the Barn. Use the search function. Search for "timing" or "GAV adjustment" or similar.
Welcome to the Barn.