Contrary to some popular talking points, Microsoft wants to sell Xbox's and get people into their ecosystem. The most effective way to do this is by making games exclusive.
No one wonders why Sony doesn't release games like The Last of Us and God of War on Xbox or PC.. because those games move consoles. Starfield will likely be a system seller.
If 1 million people buy an Xbox to play Starfield, Microsoft isn't just getting money from the console and game sold, they may possibly get revenue from other software, microtransactions or services. A new customer could potentially bring in more revenue then they lose from a single game being sold on Playstation.
Math on how Gamepass probably works below:
As for Gamepass, once it reaches a certain amount of subscribers, the revenue will cover development costs and 3rd party deals, plus be profitable. We have no idea what that number is, but supposedly Microsoft says Gamepass is already profitable.
If we assume all 23 of Microsoft's studios are making AAA games with a cost of 200M to make over 4 years, Microsoft would need to make 1.15B to recoup the costs of first party development. Let's also say that 3rd party deals cost 1.35B a year to round out the total cost at 2.5B a year.
Then if we assume the average Gamepass subscriber is paying $10 a month or $120 a year, with 25 million subscribers, Microsoft would be making 3B, more than enough to cover costs of development and 3rd party deals on Gamepass. The higher that subscriber count goes, the more profit Microsoft makes, as development costs stay the same. However, as subscriber count climbs, 3rd party deals would become more expensive.
These are just estimates on what dev costs and what not are, but you can see how Gamepass could be profitable enough to cover costs.