> Don't they have a database of every device they've sold?
A database isn't enough. They'd also need a way for that device to attest its identity to Apple, and serial numbers can be relatively easily copied (or sometimes even brute-forced).
This should be possible for newer devices using Apple's own chips, but I believe that at least non-T1/T2 Intel Macs lack any such capability.
> Why don't they check "is this device sitting on a shelf un-sold or does it belong to this account, activated"?
How would they know this? I highly doubt that every retailer in the world reports sold devices' serial numbers to Apple.