Hi Lolek,
There's multiple kinds of "locking" on devices. Click on the links below to find instructions on how to deal with your specific situation:
1) iCloud: Activation Lock - Activation Lock for iPhone, iPad, and iPod touch - Apple Support - This is a security feature so only legitimate (i.e., not stolen) redistribution of devices is possible. See: How to remove Activation Lock - Apple Support - 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 --> If you forgot your iPhone passcode - Apple Support
3) Carrier lock: Read this link on "How to unlock your iPhone for use with a different carrier" - How to unlock your iPhone for use with a different carrier - Apple Support - Only some carriers offer the ability to unlock iPhone for use on any carrier. Follow the instructions in this article to unlock your iPhone.