

The guardrail can serve the don’t-drive-off-embankment function equally well positioned before the sidewalk. The problem is when an out-of-control car strikes the guardrail at a glancing angle, it takes a long time (by design) to grind down to a stop. This creates a bowling alley effect. The guardrail keeps the speedy car centered right on the sidewalk. Any human bowling pins are toast. Some of the most horrific traffic death videos I’ve seen involve that. Whole families wiped out.
Pedestrians are much more terrified of bicycles than cars, makes sense to put the guardrail there to protect them from vicious cyclists.