How Do Custom Support So Many Phones?
CyanogenMod/LineageOS and other custom ROMs can't run on every device either. They have different versions for different devices. For example check this list for the newest LineageOS-compatible devices.

The same version can't work on every device, because the operating system (in this case the android) have to include the drivers for the specific device it will ran on. An android version which would include all the drivers would be illogically huge.