Ah, the old issue of phones and updates. Yup, Android phones generally get OS updates for 2 years and security updates for an additional year. It just so happens that phones purchased on contract with providers generally have 2 year contracts, and phones generally remain for sale for about a year from release.
This is primarily the reason.
As for Apple, well, they operate a little differently, but generally after 2-3 years an iPhone is ready for replacement anyways. Whether it be wear and tear, dropping of support, battery issues, or what have you, 3 years is about the average life of a phone.
Now, you can take good care of your phone and have it last longer, and there are ways of getting updated OS'es on Android phones at least. You can always flash a custom ROM.
Story time: My second Android phone was the HTC Evo 4G. The thing was a monster when it was released. An absolutely great phone and I loved it. I used it for the length of its contract, then got an Evo 4G LTE. That died a horrible static electric death 7 months after I got it (sort of... long story). So, I went back to the old Evo, which was not getting updates by the time I reactivated it. So, I flashed Cyanogen Mod onto it. Latest OS, updates, and I rode out the second contract on the old Evo and by the end of it, that poor phone was really showing its age. I'd replaced 3 batteries on it and Android simply required more and more power to run. I finally retired it to light duty, 5 years after getting it, and used it as an MP3 player for another couple.
The moral of the story is that flagship hardware can last a long time, but your experience after about 3 years is going to be SUPER rough, to the point that picking up a new phone is generally a good idea. If for no other reason than sanity.
Today I have an original Pixel, and I enjoy the regular updates, but it is past 2 years old and showing its age. The battery life is getting worse and worse and the Wi-Fi doesn't work quite right all the time. It hasn't lived a hard life either... well aside from the cold (no noticeable scratches on the screen!). I expect to get a few more months out of it, more than that and I'll be happy, but it IS in its twilight months for usability, and really that is just down to wear and tear. I have no idea when Google will stop providing updates for it as it has been updated to 10, but that doesn't matter, the phone is just long in the tooth.