Hello,
If you are using iOS or iPadOS 15.2 or higher, click here --> If you see an iPhone or iPad unavailable message or Security Lockout screen - Apple Support
How to remove your iPhone, iPad, or iPod touch passcode without a computer
- If you forgot your passcode, you can use your Apple ID and password to erase and reset your device.
If you are running an earlier iOS version, click here --> If you forgot your iPhone passcode - Apple Support
However, you may have more serious issues awaiting you. Was the device signed out of the ID that was signed into it previously? If not then realize it will be required to reset the phone. If you do not know the required information and you are not the owner, get the owner of the account to remove the lock (the section: "If you no longer have your iPhone or iPad" in: What to do before you sell, give away, or trade in your iPhone or iPad - Apple Support ) , or return the device for a refund, or recycle the device. The device is otherwise useless to you. If the owner is unknown and has not provided contact information as a message showing in the login screen, there is no way to contact the owner unless the person who gave you the device knows them.