Android/Google tried to make this a bit easier through Project Treble, which is like a “core” of android that can be easily updated, then vendors build their modifications on top of it. It’s pretty widely adopted now, but that doesn’t stop companies from deciding they don’t want to support hardware from three years ago even though it is still compatible with the latest Android core.
In the EU that isn’t as much of an issue when it comes to Android because they mandate that the bootloader must be unlockable (compared to the US at least, cough SAMSUNG cough). So as long as the device is somewhat popular, you’ll always have updates through custom firmware like LineageOS.
Doesn’t help Apple, though they’ve been… surprisingly good with last generation updates lately? iOS 16 can be installed on an 8 year old(ish) phone.