There are many reasons that an airplane engine can stop running.
An engine needs fuel, air, oil, and ignition to run. Take away anyone of those, and the engine stops.
An engine consists of many mechanical parts. If the wrong part breaks, the engine stops.
An engine has a cooling system. If that system fails, the engine can stop. Think bird nest in an air cooled engine.
The engine is operated by the pilot. If the pilot does certain things wrong, the engine stops. Taking off with fuel selector on an empty fuel tank is a popular way for an engine to stop shortly after lifting off. A friend did that.
Wrong fuel. Jet fuel in a gasoline engine. Water in the fuel. I experienced a fuel line freeze up one night over the Black Hills of South Dakota. Fortunately, the fuel line from the other fuel tank was not frozen.
Icing in carbureted engines.