You have to turn off iMessage on the iPhone in Settings>Messages so that it is unregistered with the iMessage server. If you can't do this because the iPhone is no longer activated, you have to unregister the iPhone with Apple by doing the following:
- Go to: https://supportprofile.apple.com/MySupportProfile.do
- Log in if not already logged in.
- Click on ">" to the right of the phone listing
- Click "unregister"