Ransomware attacked mostly Windows XP which hadn't gotten updates since 2014.
Google follows a different philosophy with its old operating systems. Even those on older versions will get updates. Maybe not the fancy new features of new versions but they will get the security updates.
Read more about it here:
https://www.cnet.com/news/why-android-is-safe-from-a-wannacry-like-ransomware-attack/