I agree that the rent per square foot is higher in a coffeeshop than in a coworking space. OTOH, if I rent a desk at a coworking space, I expect to get 40-70 sq ft of semi-private space. At a coffee shop, I'm liable to be working at a 2-top that's barely large enough to fit both my laptop and my coffee and having the ass-or-crotch debate with my neighbors if I need to get out of my chair for some reason.
As for headcount, coworking spaces need to employ office managers. A single barista can serve hundreds of customers in a day. Per customer, a coworking space might actually need more employees.
(1) Pays for commercial retail space, which is (in many cases) more than 3x more expensive than commercial office space (which is far more plentiful).
(2) Pays for multiple people's fully loaded headcount cost to staff the shop.
I didn't point out, but should have, that the shop also:
(3) Pays the wholesale price for the coffee (which is cheap but not free) and food (which is extremely expensive) and so has worse margins than the coworking space.