The exact behavior of the iPhone depends on its configuration when one forgets the passcode. By default, there is not a passcode at all. However, Apple notes the following regarding forgotten passcodes:
If you repeatedly enter the wrong passcode, your iPhone will be disabled for longer intervals before you can try again. After too many unsuccessful attempts, you won't be able to try again until you connect it to the computer with which you last synced it.
Note: You can configure your device to erase itself after ten consecutive incorrect password attempts. This setting is off by default. It can be turned on by tapping Settings > General > Passcode Lock.
If you cannot remember the passcode, you will need to restore your device using the computer with which you last synced it. This allows you to reset your passcode and resync the data from the device (or restore from a backup). If you restore on a different computer that was never synced with the device, you will be able to unlock the device for use and remove the passcode, but your data will not be present.
How to Unlock iPhone Passcodes
If you have forgotten the passcode on your iPhone, you will have to restore the device.
To restore your iPhone -- which deletes all of your data (songs, photos, videos, apps, and so on) on the iPhone use the following directions. Be absolutely sure that you have backed up the content on your iPhone before restoring it.
Apple's official instructions to restore an iPhone are:
1. Connect iPhone to your computer.
2. In iTunes, select iPhone in the Devices list, then click Summary at the top of the screen.
3. Click “Check for Update.” iTunes tells you if there’s a newer version of the iPhone software available.
4. Click Restore. Follow the onscreen instructions to complete the restore process. When restoring, it is recommended that you back up iPhone when prompted. When the iPhone software has been restored, you can either set it up as a new iPhone, or restore your music, videos, app data, and other content from a backup.
Please also note that Apple representatives can't unlock an iPhone for you without restoring the iPhone, which will erase everything on it.