PS5 is skinny, which means it's parts have to be skinny to fit into it, and we all know smaller technology is more expensive than the same specs on larger technology. Series X is huge, with tons of space on the inside, so the parts don't have to be as small.
I have no idea who is making or losing what money on their device. A lot of that is impacted by higher ups negotiating prices with manufacturers behind the scenes. Hypothetically one of them could have, on average, gotten better "deals" on parts than the other. As to which one did, who knows?
The bottom line is it doesn't matter. GamePass will lead to butt tons of cash for MS and Exclusive games will lead to butt tons for Sony, while Nintendo makes more profit than both of them. They all go home rich and happy, and capitalism thrives as it should with investors getting dividends.