A nonprofit wouldn't have to distribute profits to charity. It just can't distribute profits
to private or public shareholders (because it can't have them). A nonprofit is obligated to reinvest any earnings towards its mission.
Not remotely an expert, this is just my basic understanding. "Nonprofit" is a pretty abused term.