To the contrary, it's actually extremely hard.
When I order, I probably get something incorrect ~10% of the time. Whether fine dining or fast food.
To deal with life-threatening allergies, you need to get that error rate down from 10% to, what, 0.000001% or something?
You're literally asking for hospital- and pharmacy-level procedures, controls, and training. Which would make restaurants far more expensive and there would be far less of them.
Not impossible, but yes extremely hard, when servers mix up orders and cooks mix up tickets and runners mix up plates and tables.
Restaurants have specific procedures for allergy meals. It's not that hard to do an extra good job when someone discloses an allergy.
Saying you have an allergy doesn't mean the server won't simply forget to pass it on. Or won't misremember the ingredients in a dish. Or that a runner won't actually grab a dish for the wrong table.
There are no magic order-to-serving procedures that are guaranteed to work 99.9999% of the time that are also easy to implement in a cost-effective way. It actually is really hard.
So what happens is everybody tries their best but there are just no guarantees, and mistakes get made all the time.
Of course it gets to a point of diminishing returns where you can only rule out so much if the risk but all it should take is proper labelling of ingredients in dishes and training to make sure these processes are followed.
As the other commenter noted, only dishes for those with an allergen need to be prepared separately