Yes, you need to do it if you are planning to sell or recycle it. Even if you securely wipe your iPhone but still leave yourself logged in, it would essentially be locked by your Apple ID. So it's always recommended to make sure that you deauthorize everything prior to getting rid of an iOS device.