What’s your usage pattern for those devices? Almost full discharge + fast charge?
Asking because I only noticed a very small degradation (judging by reported charge %) in a flagship device after 3 years. A midrange phone from 2020 with heavy usage (charged twice a day sometimes, often using a fast charger) for 2-3 years did not have noticeable battery degradation. A low-end device from 2016 had no noticeable degradation after 4-5 years. Another 5+ years old second-hand phone had some, but nothing catastrophic. The only case of bad battery degradation (shutdown at 20%, unreliable gauge, etc) I have only seen in 10+ year old devices.
This, unfortunately, has been a thing for over a decade. I was excited to discover that Samsung Galaxy S3 (i9300) is/was one of the better-supported phones for custom ROMs… until I realized that the one I have is a Sprint / Virgin Mobile version (d2spr), which looks the same but uses a different SoC entirely.
You might end up needing postmortemOS
On a serious note, you can run without a battery
Samsung Galaxy S5 checks all of these. I prefer it with Lineage 14 (Android 7), but ran it with Android 8, and it can support up to Android 10 or 11 IIRC, although later versions are somewhat slow.
Samsung Galaxy J7 (2015) might also fit the criteria, even though it’s not a “flagship”.
If you’re looking for alternate OS list for smartphones and tablets, I compiled a list.