I don't understand how trading the stocks with others (who didn't participate in the IPO) would benefit the company
I suggest studying Prisoner's Dilemma and indeed making a study of all of game theory.
(A starting place might be https://www.amazon.com/Prisoners-Dilemma-Neumann-Theory-Puzzle/dp/038541580X/ )
Stocks are a pure belief-based self-referential shared game system.
They have utterly no value, whatsoever.†
why do the people invest in stocks in the first place when (there are no dividends)
It's very simple to explain this - but hard to grasp.
(1) It's a fact that you, Archer, have realized that stocks have no inherent value and it's only a game-theory milieu.
OK - you can agree that (1) is a fact.
However,
(2) It is a fact - again this is a fact - that most adults on Earth believe that Google stock will be worth a lot in one year and in ten years. That is a fact.
You must comes to terms with the basic tension between 1 and 2.
Looking at point (2), let's say that you are "not" one of those people. Agreed?
So (1) is true, and furthermore you are not one of the people in (2). That's completely true. But. Is point (2) true?
Take point (1) and put it in a suitcase in your head. Point (1) is completely true, but it does not influence or affect point (2). Point (2) is incredibly true. It is deeply and profoundly true. Point (2) is as true as and simple factual statement like "London is in England".
Point (2) is so true that you can bet all your wealth on it.
You may think you know "more sensible" investments, say, real estate. But I can tell you 100 reasons why real estate can go wrong. (Note that to begin with the only reason real estate is stable is because of national governments who shape the nature of the land title.)
Versus that shakyness, we have the absolute fact of point (2).
† Stocks have one and only one actual value - which is absolutely abstract and theoretical. If some entity wants to take over Google, they can sometimes do that by "purchasing a lot of the stock". Not only is this "the only value" of stocks, it is the definition of stocks, it is what they are. Of course, this is all-but abstract and theoretical - how often is Google taken over? But yes, this is the one and only "theoretical underpinning" of what stocks are other than a large self-referential game theory milieu.
Note that if you own "a share" of a normal entity (not a public company) that is quite different. So, if you own 30% of a coffee shop, you quite literally "own" some thing, just like owning a car or a sofa. Shares in public companies have no relationship, at all, to this concept. Only in the extreme abstract (some classes of) shares in certain quantities may have voting rights on certain issues and, as mentioned, if some party P wants to "take over" the company they will have to buy a certain percentage (1%, 12%, whatever) of the shares which (in an incredibly abstract sense) means there may be purchase pressure in the future. Other than that, as mentioned, shares in public companies are 1000% psychological - pure game theory.