They also have basically zero user-acquisition costs, on both the user and advertiser side. CAC (customer acquisition cost) is usually the largest variable cost for most businesses. Things like server costs, electricity, etc. are tiny in comparison. Cut CAC and your margins skyrocket.
Indeed, the reason why Google & Facebook are profitable is because they're a very effective way of cutting CAC for other businesses. Their revenue is another businesses's marketing spending, and yet they're still better than the alternatives for driving customer conversions.