To summarize:

Never enter a wrong code more than 3 times, or your phone may hard-lock to the original carrier forever.

If you are locked out of your phone due to a forgotten PIN, pattern, or password, you can use these methods:

Contact your carrier. Most will provide an unlock code for free if your contract is completed or the phone is fully paid off.

: If your phone is signed into a Google Account and has internet access, visit the Google Find My Device site