How F1 ended up with a one-car grid at the Hungarian Grand Prix

It was one of the most unusual sights in modern Formula One history as Lewis Hamilton lined up on an empty grid, waited for the lights to go out and raced himself down to Turn 1. But how did it come about and could it have been even more farcical?