Apple ID password or the phone passcode?
Password.
If you forgot the Apple ID (iCloud) password, enter the Apple (iCloud) ID, and click Forgot Password. See if you can get a Rescue or Notification email option if necessary. Link to contact Apple Support at the end of the 2nd article.
Apple ID - Manage
Apple ID – Forgot Password *
If you have 2 Factor Authentication enabled, if you can't recover the password using the steps above, you will need to use Account Recovery. The Recovery Process is an automated process and the length of time it takes can vary a lot. Apple ID Support can only answer your questions. They can't intervene in or speed up the process. The article below has some suggestions to shorten the time the process takes.
Apple ID - Recover your Apple ID with two-factor authentication account recovery. *
If you have changed your password, have you followed the steps in this article on all devices/computers?
What to do after you change your Apple ID or password - Apple Support. *
Passcode.
See the Apple Support article(s) below for IOS 15.2 or later..
Passcode - How to reset your iPhone, iPad, or iPod touch when you forgot your passcode (IOS 15.2 or later). *
ASC YouTube for how to restore your iPhone if you forgot your passcode - Apple Support. -
See the Apple Support article(s) below for earlier than IOS 15.2 .
Passcode - If you forgot the passcode for your iPhone or your device is disabled. *