How to disassociate AppleID from an old iPhone?
Here is the correct answer for you. It is currently the highest-voted answer to a very similar question which was asked previously.

Go into Settings > Messages and halfway down choose Send and Receive. Tap your AppleID on the top of the page, then choose Sign Out.

If you really are giving away your phone there are several other places you ought to sign out from as well:


Settings > FaceTime
Settings > iCloud
Settings > iTunes and App Store


If you'd prefer to reset the phone to its factory defaults, wiping all your data, apps, music, etcetera, then use Settings > General > Reset > Erase All Content And Settings. Then the phone will be brand new like you just bought it from the shop.