The high price of iPhones should cover all development costs of iOS. iOS is not really free. You pay for it and for all future updates with the price of the iPhone.And you know that the $99/yr developer fee doesn’t cover all the development costs of iOS since that can be the cost of a simple iOS app, while iOS is much bigger.
Both sides profit from the existence of the Developer Program. Developers get a platform to publish the apps. Apple gets a lot of apps for its platform. Without those developers Apple would have to create all those apps on its own. So even without any fees both sides would profit a lot from that deals. Apple just uses its market power though to squeeze money out of the weaker side of the deal.