The deal is called Find My iPhone, it is a lock that permits ONLY the owner of a device to unlock or reset it. If a device gets stolen, this enables the owner to lock or track it.
If a device is legitimately sold, the original owner MUST deactivate Find My iPhone before passing it to the new buyer. You, as the buyer, must ensure that this has been done. Do not buy a device where you have no hope of a refund if you find the lock has not been reset - i.e., don't buy from a stranger off the street, from Craigslist, or any other method where you cannot physically check the device before you buy it, or if you cannot get a refund.
Matt