It never was free before modern internet advertising, the costs were just hidden somewhere else. I remember the time before that... IRC servers and a lot of code hosting (SourceForge, Linux distro repositories) were paid for by volunteers/donors/universities, newsgroup servers were ran by ISPs and paid for by ISP customers, forums, MMORPGs, general online game servers and the likes by donations or sometimes just the pockets of whomever in the community had some money to spare, and a lot of the warez scene was just plainly skimming off of others: STROs for hosting, phone dialer scams and credit card fraud. Additionally, some sites made small, direct advertising deals with relevant companies (say, a forum about car DIY could run banners from a dealership).
A lot of stuff that we take for granted today - especially animated content beyond short GIFs - simply was unfeasible because the amount of money you needed to cough up was so immense. The influx of money through modern advertising, especially Google Ads, made many things even possible in the first place.
Also, times (and legal responsibilities) changed, driving up the cost particularly for anything involving UGC. Blog comment sections, guestbooks and the likes got impossible to moderate due to spam, and as that vanished, so did blogs in general. Forums had to deal with CSAM spreaders hiding out, and then came terrorists and the regulatory responses towards them requiring very strict timeframe for the removal of such content... it's a real effort to host anything beyond a static HTML site these days.