If you restore a previous backup to a new iOS device, passwords stored in Keychain (including WiFi passwords) are not transferred by default. Re-entering all passwords your iPhone used to remember can be a time consuming and frustrating task.
Luckily, iTunes has a feature for power users that allows you to encrypt backups. When restoring from an encrypted backup to a device other than the one the backup originated from, passwords in Keychain will be restored too. When restoring to the same device only, it's not required to encrypt your backups. Though, I highly recommend to encrypt backups to prevent damage in case your computer gets compromised.
This is a screenshot of iTunes for Mac configured to encrypt backups:
Keychain (this includes email account passwords, Wi-Fi passwords, and passwords you enter into websites and some other applications. If you encrypt the backup with iOS 4 and later, you can transfer the keychain information to the new device. With an unencrypted backup, you can restore the keychain only to the same iOS device. If you are restoring to a new device with an unencrypted backup, you will need to enter these passwords again.)