In the United States, a non-profit does not earn money for owners or investors. NP's do make money via donations and services provided. While many NP's make very little money or mostly distribute donated funds, other NP's can make large amounts of money. Money retained in excess of expenses, must be used to further a NP's mission.
A NP Hospital uses its excess funds to provide free services to those who cannot afford healthcare and does community outreach and eduction.
Mozilla uses its money to supports other OSS projects, advocates for OSS.
(This is a very simple explanation with many details of how NP's operate ignored, or the various legal types of NP's.)