It's a very wide combination of things, partially driven by greed.
In IT we have a software/hardware development software that feed into each other as a vicious cycle. When new hardware comes out, software companies want to take advantage of those features. So they jam as many features as they can justify that use that hardware. Similarly, when new software comes out, hardware companies need to produce accessible hardware with enough of their own features that can keep the symbiotic relationship going.
Then we also have the user-demand issue. Every time a company brings out [x] feature, every other company thinks they need to bring out that feature whether users actually want/need it or not. This is especially worse in the mobile world where everyone looks to Apple, Google and Samsung as the "innovators". To keep on top of these new software features, the new hardware has to come with it or the phone gets slowed down - computers suffer less from this because the hardware isn't as complex.
Finally. phones aren't really "built to last". You have a battery you're constantly using every day, screens that are getting wear and burn from being on all the time, storage limitations, app bloatedness. If you get 4 years out of a phone, you're doing well, but you're ultimately due for a new one, regardless of how well you take care of it. I've played around with custom Android builds designed to give "more life" to these phones. Between the battery, and obsolete hardware, you're essentially just keeping it on life support. That's just part of the modern world.
For the other side of this, Microsoft pushes a new version of Windows every couple of years and supports them for roughly 10, you're correct. But this is largely because of how much they're used for day-to-day stuff that can result in being open to vulnerabilities and viruses. It's a massive ecosystem, compared to the rectangle that you replace every few years. Yes, phones can be vulnerable to viruses, but there's less of an attack vector for them. Your computers are literally connected directly to other computers, file shares, and other things that will literally cause life to grind to a halt (at least corporately) if they die. Your little pocket rectangle, you just trash and go to the shop and buy another one.
As for MacOS, I'd have to look into the lifecycle, but one thing I will give Apple - their Mac hardware tends to survive for a while as long as it's taken care of. iPhones? Not so much.