They get charged by the networks, so your local affiliate pays CBS/NBC/etc a bunch of money for every cable/satellite/streaming viewer (I don't think they pay for OTA, but I don't know that for sure)
The networks raise their prices so the affiliates have to.
The money the networks charge mostly goes to pay for sports contracts like NFL, college football, basketball and so forth.
I'm still waiting for the whole Sports Industrial Complex to collapse when people are no longer willing to pay through the nose for it. Any day now...