This is one of the most common things that happens to a lawn mower. You pull the rope or turn the key and it starts and then dies quickly. It may run for a few seconds or less than a minute and then it dies as if you flipped a switch.
It almost always turns out to be a fuel problem that is causing this issue or more specifically, not getting enough fuel.
If your lawn mower dies after starting, the first thing you want to do is remove the gas cap and listen for a vacuum type sound. Kind of like when you pull the tab on a can of pringles. If you hear that vacuum sucking sound, the gas cap vent is not working and it needs to be replaced.
If the gas cap is not the problem, you could have stale fuel or water in the fuel. A fuel sample should be taken from the fuel line going to the carburetor. Pinch off the fuel line and then disconnect it from the carburetor. Then allow fuel to flow into a small glass jar and if you see water collecting or the fuel is cloudy, it is bad.
If the fuel is good, then the problem most likely is in the carburetor and it will need to be removed and thoroughly cleaned. After cleaning the carburetor, re-install it and then start the lawn mower.
If it runs better but is now surging up and down, then the carburetor still requires cleaning and pay particular attention to the main and idle jets. Also be sure that your carburetor gaskets are good and that the bolts are tight holding the carburetor on.
Other things can cause your lawn mower to start and then die, but in most cases the fuel is the problem and is a problem that can be solved.