To be fair, part of it is due to supporting the SoC, and that means dealing with Qualcomm. Samsung has the advantage of being able to develop their own SoC's and so can support them for far longer with updates and such
This excuse doesn't hold much water anymore since the Pixel 6 is based on Google's own SoC, yet it also only offers 3 years of Android version updates.
Why can't Google do like Apple and offer many years of version updates? The iPhone 6s is still running the latest version of iOS.