Sometimes it does happen. To name one example, I decide to change iPhone lock screen passcode, and a day later I forget it. Also, this method works if you forgot the Restrictions code. Make sure you have your iCloud up and working, so that you can restore important data later. Then, follow this advice…
Here’s what you can do:
1. Turn off your iPhone
2. Hold iPhone’s Home Button and keep holding while connecting to PC/Mac with installed iTunes until you see a sign on the iPhone’s screen that tells you to «Connect to iTunes»
3. When the iTunes screen pops up, it’ll say that it has detected an iPhone in a Recovery Mode and will also ask you whether to Update iPhone’s Software (iOS) or to Restore it. If you press Update all of your data and settings will be saved, so if you’re trying to get rid of the forgotten password, don’t press this option. Instead, you want to Restore iPhone, so that all data will be erased and it’ll be just like a new iPhone.
4. Click the Restore button (then click all the «Next» and «Adree» buttons). Then the newer version of iOS will start to download. Wait a little and Don’t Disconnect the iPhone.
PS: If you don’t want to lose stuff from the iPhone or iPad, there is one chance I know you might save the data.
If sometime previously you’ve set the device to «Automatically Sync With iCloud When Connected to Wi-Fi and Charging», then you can save your information without even knowing the Lockscreen Code. Just turn on iPhone’s Wi-Fi and wait for it to connect to the Wi-Fi network it remembers from your previous «Wi-Fi parties».
Once this step is done, connect the device to a wall charger and leave it there for a couple of hours (the more data and the slower the internet, the longer you’ll have to wait). THEN you can freely erase an iPhone to factory settings, as described above.