I have seen this issue in a 172. I watched a guy start the engine, taxi the full length of the 5500 foot runway, do a runup, wait a couple minutes at the end of the runway, line up and advance the power for take off and was just lifting off when the engine quit. Fortunately just landed straight ahead. The fuel selector was in the off position the whole time.
Brian
This is due to poor maintenance.
The fuel strainer should be opened every 100 hours or annually for cleaning and inspection. This requires the fuel selector to be shut off. If the valve is internally leaking, fuel will continue to flow from the opened strainer onto the floor. It might be a persistent drip, it might be a trickle, it might be enough to get the airplane off the pavement.
So the mechanics are obviously slack here. The strainer either isn't being cleaned---and I have encountered strainers that I could barely get apart, bowls seized on by not having been serviced in a very long time---or they ignore the leakage while it's open.
Opening, cleaning, inspecting and reassembling the strainer takes maybe ten minutes.
The 172's fuel selector:
The cam (#4) pushes on the smaller steel ball (#15), to push the larger steel ball (#16) off the seat to open the valve. That seal is a rubber O-ring (#17). That O-ring, one for each side, left and right, ages and deteriorates and shrinks and cracks and crumbles and doesn't seal anymore.
Drain plug (#22) is supposed to come out every 200 hours and the accumulated crud that settles in the bottom of the valve drained out. That valve is the lowest point in the whole system. I have found those plugs in 40-year-old airplanes seized in there tight, never having been removed. The '96 and on 172s have a quick-drain there, and I put quick-drains in our legacy models. I found amazing amounts of goop and stuff in those valve after I got the plugs out. I had to drain the tanks so I could take the valve out to fix everything.