There are more coffee shops than libraries. Your path to a coffee shop is generally shorter than your path to a library.
This problem gets even worse when you add the dimension of time. Libraries are closed a lot. Philistines keep cutting their funding, and they respond by shortening their hours. Unless your working hours coincide neatly with library opening hours you'll sometimes need an alternative.
Finally, there's the social dimension. It's not easy to start a random conversation in a library, and it's essentially impossible to answer the phone. (Unless you are a big jerk and your local librarians are insufficiently ruthless.) Now, if you're trying to program such an environment is a godsend, but if you're trying to run a business programming is often the least of your problems. You have to do sales and marketing and client management and the occasional round of procurement or insurance shopping or whatnot, any or all of which may require you to talk on the phone occasionally.
That said, whenever I'm near a library during its opening hours I head over there instead of towards the coffee shop. Here in Boston the library situation is good: The public libraries are fairly numerous and popular, and some of the more enlightened universities let civilians into their libraries, which have longer hours and better study spaces.
Maybe all the coffee shops I like are just way smaller than the ones you all use.
Mostly: I had great success working from libraries, and I know that many coffee shops do not like people working from them all day.
Well, the most obvious reason would be for the coffee.
Seriously though, I think this varies by city. In Seattle, it's very much culturally accepted to work from coffee shops; it's practically what they're there for.
Not my experience at all.
Coffee shops on the other hand are usually fairly quiet in something like a starbucks (really depends on location and time). Of course when it's rush hour this all changes.
My hometown has >1mio population, 3 universities and a lot of students occupying the libraries. Coffee shops can be a comfortable alternative.
Unless the coffee shop is dead, they don't want you there.
The library on the other hand is funded in part by utilization, and very much does want you there.
The library is quiet, is designed to provide work spaces, far larger, and generally very pleasant to be in. And it's free.
The coffee shop is loud, is certainly not ergonomic, cramped, and often jarring.
Also, I don't know what the word is for an ostensible who brings their own lunch daily to an establishment that serves any kind of food, but I'm sure there must be a word for it. Sheesh.