Apple historically has been a tiny player in terms of share. They are able to punch over their weight and be profitable making hardware. The original iMac, at the company’s nadir, was the #1 computer model, which gave them supply chain advantages in the market.
The other thing is that while Dell is stuck with Windows, Apple owns a few platforms. They sell cheap iPads as their entry product.
You may not like the strategy or the particulars of it at a given time (ie shipping a defective keyboard for years for inscrutable reasons), but they have a differentiated strategy because that’s what makes sense to them. They are not a commodity. Dell, HP, Lenovo can’t do that because they are merely a channel for delivering Windows - just like Exxon or BP are middlemen brokering gasoline, the only way to make more money is to ship more stuff.