Most common middle- and upper-tier phones, as well as any Pixel and Fairphone (thanks to being more open) will get a custom ROM with updates 8+ years after the release, and you can buy a used 5-year-old phone quite cheaply.
Typing this on my 10-year-old Sony Xperia Z with Android 13. It cost me $0 (found in e-waste) including a data plan (owner forgot SIM inside). The camera has low sensitivity and dust in it and the battery is worn, but everything else is decent. I will open it some day to fix the problems, a replacement battery cost me $10. There is even 4G and NFC, and the 1080x1920 screen is nearly "retina-density" at such small size. I decided to not use the SIM as it could be criminal, and I have my prepaid one in s dumb phone, but I use it for entertainment - the phone fits in my hand and the design is quite timeless. The CPU is a little weak, it cannot decode 1080p30 or 720p60 video in real time, and gets hot quickly on demanding websites.