The root reason for the massive difference in performance is that F1 engines have a very different set of constraints. Performance is favored over almost everything else. The budget is astronomical. The engines don't have to be optimized for mass production. They only have to run on a very specific blend of fuel. They don't have to pass emissions tests. They only have to last a few thousand miles, and it's fine if they require crazy amounts of monitoring and maintenance. A narrow power band is acceptable. And of course, they can fail in dangerous ways.
A side note: production engines can still generate ridiculous power in small displacement, but manufacturers usually don't have a reason to optimize for that. In the late 80s, Japan passed a law restricting beginner motorcycle riders to 250cc bikes. Honda, Suzuki, Kawasaki, and Yamaha all built the most ridiculous 250cc sportbikes they could engineer. Some revved up to 19,000 RPM and produced over 50 horsepower[1].
Compression ratio (the 'squish' in an engine's 'suck,squish,bang,blow' cycle) is >~14:1. Dynamic compression (once you factor in the compression of air caused by the turbo) is much higher. This is largely due to running a higher octane fuel which keeps preignition at bay. Your typical road car has around a 9:1 compression ratio.
Secondly, peak operating RPM is triple the average road car. Horsepower is '(torque * RPM) / 5252'. With the engine spinning at nearly 21,000 RPM, the neglible torque from the small displacement starts to add up. Again, your average road car sees about 6,500 RPM.
Lastly, for comparison, the best road cars rarely see over 120hp/liter in normally aspirated form. And 250hp/liter on 93 octane is about the limit on well tuned turbo cars.
This is largely simplified, as quite a bit of engineering is needed to get even above road car values.
Even without exotic engineering highly-boosted turbocharged 2.0L street-car I4s can put out upwards of 500 horsepower at 7-8000 RPM. Formula One builders take things to the next level by building more advanced rotating parts and using pneumatic valve springs to allow the engine to spin all the way up to 15,000RPM with an almost linear increase in horsepower as they travel up the powerband.
I'll call bullshit on that. After whatever you've done to a stock 4-cylinder motor to make it output 500 horsepower, you've got a racing engine, with all that entails. It's not properly a "street car" part anymore. :)
But like anything that burns brighter, the wick shortens faster. So these motors won't stand more then few hours of operation vs a consumer car that is made to withstand few years.
Look at rotor engines. Those were great small 1.3L motors with huge power outputs. Obviously not as reliable as piston motors. However I always wonder why humanity complicated motors and created so many moving pieces when all we had to do is build an electric motor from the start.. a magnet wrapped around a coil under current. Less moving pieces, less things that can go wrong and longer life span.
Nethertheless one cannot beat the jet like sound of F1 piston engine under full power smashing down the straight!
While engines on road going cars have to handle hundreds of thousands of Km, F1 engines only need to last a few thousands.
Based on that fact and lower tolerances they can push several metrics that are key to the power output of the engine such as RPM a lot further than the automotive industry.
Also your engine has to last the lifetime of the car. F1 drivers are allowed 8 engines a season.
Obviously totally different design goals.