Other console makers make a profit on their consoles as well. Typically it's either a small margin at the beginning, or maybe they're eating it somewhat, but as time goes on the components get cheaper, production is improved, or they make revisions to reduce complexity in the circuit boards, or they release a newer smaller version of the console as well. But it's not fair to say that Sony and Microsoft lose money on their console hardware but Nintendo doesn't.
Want to play Zelda? You have to pay Nintendo at least $260. $100 more if you want to play on something better than a Switch Lite.
Unlike Sony and Microsoft, Nintendo actually makes a profit on their hardware sales as well as game sales.