Xbox is where it is because they destroyed their momentum going into the most important generation ever.
Starting with the ps4 and xbone, Sony and MS began the foundation for the digital ecosystem that will carry on from gen to gen going forward.
It's almost impossible to convince someone to switch from one ecosystem to another when it means leaving an entire library of games behind.
Just look at Steam as an example.
MS has tons of good momentum going into the last gen and lost almost all of it with their poor hardware, marketing, and development decisions.
People flocked to the ps4 and established large digital libraries which have now carried into the current gen and will continue into the next.
This gen, they got the hardware and marketing better but lacked the exclusive catalog that would have been needed to get people back. It would have been slow and hard but they could have done it. Instead they now have the good exclusive catalog but instead decided to make it available everywhere. Great for keeping money coming in but not great for getting people to buy your systems.
Why would anyone with a ps5 want to buy and Xbox when you know you are going to get the MS games ?
I wonder though, how many PS4 users got a significantly large digital library. Large enough to dissuade their owners to "switch" ecosystems. I mean, we know from marketing research most people buy 3-4 games per year tops. Most of them buy games that have yearly releases like sports and COD.
On top of that people started playing F2P on PS4, games like Destiny, Fortnite, Apex Legends, etc. All those games don't amount to any kind of library you care to hold on to. Physical media was also still fairly strong during that gen. And if you made the switch to Xbox or PC is not that big of a loss to get some of those games like your staple GTAV again for cheap like $15.
So I don't entirely buy that belief which Phil Spencer himself holds that Xbox lost the console war when people built their digital libraries on PS4. I mean, you don't have to make people "switch" and abandon anything, you just need to give them a enough compelling reason to also join your ecosystem, buy your console, your games. Gamers buy multiple devices, they're attracted to what each of them provide.
Xbox never gave players franchises to get attached to, or even expectations of getting some great games down the line. After the first year year, year and a half of Xbox One, despite the troubled launch and bad publicity they still released some good exclusive games.
They released nothing to make people interested in Xbox since then. Xbox Series is a bigger failure. Consider they launched with zero (0) exclusives ( a first in consoles history!), and a whole year later they released Halo Infinite which failed to live up to the name and expectations, that franchise was already dead to be any kind of ace for Xbox. Then absolutely nothing in 2022 (it was over by then despite the usual vocal minority saying otherwise), then who knows why they were hoping Starfield would correct the course, talk about being out of touch. And the last hail Mary was putting COD day one on GP. See how that one worked out.
In short, their problem always was they didn't have great exclusives, even if they were only "console exclusives" a lot more people would have joined Xbox.