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.
Here's a 2 year old video comparing a $550 PC (with RX480) to PS4 Pro: https://www.youtube.com/watch?v=HueyUmSHrdo
Also, PS4 Pro specs list its GPU perf at 4.2 Tflops, while a GTX 1080, worth $499 and predating PS4 Pro by half a year has 8.2 Tflops. It's in the ballpark of 3.8Tflops of GTX 1060, MSRP $249.
The PS4 Pro's CPU at 2.13 GHz is also not what one would call punching above your weight. There are cheap i3's more powerful than that.
A console's value is a very dubious proposition if you are in a country which is given a favorable regional pricing by Steam.
It's the same reason people pay a premium for Apple products even when they're strictly less functional - they're nicer to use.
Apple products have quite a few things going for them other than the smooth UX, I remember being surprised that a lot of non-technical people thought that they could not get a virus if they used Macs instead of PCs.
Heck, look at what Nintendo has done with Breath of the Wild on the Switch hardware.