This is a very good question. Although it looks simple at first, but accurate understanding requires a little bit thought. I think you mentioned several truths (facts), such as 1. it's zero sum game, one's gain is the other side's loss and your explanation makes perfect sense. 2. Investors are rational, and they all have their own positive expectation.
However, when you put them together, you feel very confused. There are several aspects that can help you better understand this. First, when two sides enter a contract at time t. There are several reasons for this: a) the buyer or seller could have different view on the underlying price movement from time t to maturity T; b) the buyer or seller could enter the contract at time t because they want to realize their gains or loss based on their view at time t; c) the buyer or seller just have to take some of the positions maybe due to other hedging purpose. Second, although the whole option game is zero sum, but it doesn't mean that whenever there are two people enter one contract, acting as the buyer or seller respectively, one gain is the other's loss. The zero sum game is considered for the overall market (all the option players at any time t).
Hope this helps.