Hello,
There's multiple kinds of locking on devices and how to deal with each kind depends upon what exact messages you see. Typically #1 below is the most often encountered with a previously used device, but you saying "4 digit code" suggests you need to do #2.
1) iCloud: Activation Lock - http://support.apple.com/kb/PH13695 - This is a security feature so only legitimate (i.e., not stolen) redistribution of devices is possible. See: Turn off Find My iPhone Activation Lock - https://support.apple.com/HT201441 - If an activation lock was put on a device, only the owner of the account that applied the lock can remove it. Get them to remove it or return the item for a refund.
2) Device lock: "If you forgot the passcode for your iPhone, iPad, or iPod touch, or your device is disabled" click here --> https://support.apple.com/HT204306
We can provide more details about dealing with both kinds but to keep this reply short I won't post those until I know which one you need to use.