When buying an Android phone, or tablet, you need to pay a lot more attention to the issue of security updates speed and longevity than with an Apple device.
Most of the articles listed on the first page of the search below are worth reading to understand what manufacturers/phones are the best for security updates. You want a phone manufacturer that will quickly pass on to you the security updates that Google releases, and will continue to do so for as many years as possible. When the Android security updates stop getting to your phone, it's good only as a paperweight.
With Apple you have much less to think about, and a phone will always get 4 or 5 years of updates. Some 5-year old iPhone and iPad models are getting 6 years, which is unusual. And Apple is even providing occasional security updates to devices on iOS 12 (and above), which way behind the current iOS 15.