As a point of comparison, Microsoft ships its OS across a variety of manufacturers and largely keeps it maintained across them (give or take some exceptions like enterprise environments & the like).
Even unlocked Android phones purchased independently of carriers have inconsistent lengths of support, so it doesn’t seem to be entirely a result of carriers, so…What happened here?
Cause the brand of the phone decides how long it stays updated even if its running stock android. So lets say the average life of a Samsung is two - four years why support it longer when you can let it fall outta support to further create a need to upgrade.
Lots of roms let you run really modern android on old phones cause they put in the work. But a company turning a profit does really have a need to support phones for a long time.