Most open source projects will have a donation page / link, so it relies on people feeling compelled to donate because the software provided is useful to them.
Lemmy for example has options for financially supporting its development. Some Lemmy instances also feature a link to a donation page to cover the hosting costs.
Some have an organisation behind it, like Firefox has the Mozilla Foundation to finance it. Actually it’s the other way around, see ahal’s comment below
The team behind VLC has a “for profit” branch that adapts the video software for companies, allowing them to also finance VLC’s development in addition to donations.