Sony and other hardware makers also sell a lot of accessories, which often have huge margins too. The online services they sell also have big margins.
Selling hardware at a loss is one reason that consoles have always punched much higher graphically relative to price.
If the PS5 comes out for $500, it probably cost Sony around $700 to make it, and this is with getting massive volume discounts (guaranteed CPU and GPU contracts over several years with huge volumes of orders coming in) that your PC can't get.
And then because consoles only have one CPU and GPU combo to program to, you can get a lot more out of the hardware than you can with a PC.
This is why when the PS5 and the new Xbox launch, it'll probably give you better fidelity than a much more expense gaming PC -- and it will only get better visual fidelity for years to come as developers learn to exploit the architecture better.