Easy, they own shares. For example, the nonprofit Mormon church owns 47 billion in equity in private companies including Amazon, Exxon, Tesla, and Nvidia[1].
Nothing stopping a non-profit from owning all the shares in a for-profit.
[1] https://finance.yahoo.com/news/top-10-holdings-mormon-church...