How does Android account for hardware changes in each individual device?
Most hardware-specific code doesn't come from AOSP1, but is provided by the corresponding manufacturer (often as so-called binary blobs). This is especially true for "exotic components" (like your "fingerprint sensor") – but also for more common components as the camera. Which BTW also is one of the reasons why there isn't a "generic ROM" fitting all devices.2



1: Android Open Source Project
2: see Why is it that Android still can't be installed as regular OS? and Can I install any ROM for my Android device?