To access a phone after forgetting the lock code, use a computer program synced with the phone to either bypass the lock screen or erase the phone, as of 2015. The exact process varies depending on the phone. Phones typically don't allow users to recover forgotten lock codes. Instead, the user creates a new code after accessing the phone.
With iPhones and other Apple devices, you must erase the device to erase a forgotten lock code. If you've created a backup, you can restore your device's data. If you've synced the device with iTunes or iCloud, you can use either program to erase the phone. Otherwise, plug the device into a computer with iTunes, and then hold the home and sleep/wake buttons until the phone goes into recovery mode. Select the restore option on iTunes, and proceed through the process to erase the device.
For Android devices, visit Google's Android Device Manager online, and select your device. Select Lock, enter a temporary password, and then use that temporary password to access your phone. If you haven't set up Android Device Manager, an alternative option is entering the incorrect code five times and clicking Forgot Password on your device. You can then enter your backup PIN or your Google account login information.