1) Special ad positions with front-page placement (currently #22 is "Willing (YC S15) Is Hiring a UI / UX Designer" https://willing.com/designer , a privileged post that can't be voted or commented on)
2) The moderators can and sometimes do intervene by removing certain comments that are critical of YC companies.
Comments make the forum more interesting to the community, which increases eyeballs and makes the front page spots more valuable. And shaping the discourse helps with damage control when necessary.
YC doesn't make money directly from the forum. But neither does AWS from their docs.
If you have a problem with a company making money directly from your content, why doesn't it bother you if they are gaining something else off you like influence? Do you think HN confers zero value to YC?
Engineers generally have a natural tendancy to fix things, and documentaitons are worth fixing. And it also helps their future work.