If you mean the iPhone’s screen passcode, you can erase a locked iPhone with a computer even when you cannot unlock the phone. That does not remove Activation Lock or let you bypass the Apple Account that owns the device.
- Turn off the iPhone.
- Connect it to a Mac or Windows PC while using the correct button for your model to enter recovery mode. Keep holding the button until the recovery-mode screen appears.
- On a Mac, open Finder. On a Windows PC, open Apple Devices.
- Select the iPhone and choose Restore.
- After the erase finishes, set up the iPhone and restore a backup if one is available.
If Find My was enabled, setup can still require the Apple Account previously associated with the iPhone. If you do not know that password, use Apple’s account-recovery process. Erasing the phone is not a way around Activation Lock.