the concentrated syrup is indeed much cheaper to get to the retail location, and typically the retailer does make a large margin on fountain drinks. at a restaurant, this typically offsets the very tight margins on their other offerings, similar to alcohol.
tangent: I've been to some restaurants that charge $5+ for a fountain drink, presumably to mitigate the lost profit on alcohol. it would be interesting to know why the business model is that way, instead of just pricing a moderate profit into both food and drink.
In regards to your tangent, it's because drinks are not the attraction, so people are relatively price-insensitive to (or price-unaware of) them. People think "I want a burger", price-compare burgers, and choose the place with the $5 burger over the place with the $7 burger. They don't notice that their side and their drink are each $1 more at the $5-burger place, and that both meals cost the same at both restaurants. Instead they think "geeze, I'm glad we went here. Who'd pay $7 for a burger? That place is a ripoff."
That's only compounded by the tendency for drinks and sides to be impulse-purchases - easy up-sells that no one walked in intending to consume. And, if choosing the $5 burger has maybe embedded the idea that your place is "cheap", then so much the better, as that makes them likely to spend a little more than they would have at the other place: "I saved $2 on the burger, so I can afford an extra side!"
Tl;dr: Commodity restaurants are trapped in an equilibrium where food has to be a loss-leader for sales of drinks and fries.