I have an old Sprint iPhone 4s that hasn't been under contract for around a year now and I have a friend on T-Mobile whose contract doesn't end for another year. He still has a flip phone so I want to give him the old iPhone. Is there a way to unlock the iPhone if it is no longer under contract?
Unlocking is trivial with carrier support.
Here is Apple's article on how to proceed technically once your carrier has unlocked the device:
We have a nice thread on this Sprint to T-Mobile shift here:
Assuming your account was in good standing while the phone was under contract with Sprint, you would have to call Sprint Customer Care to get it unlocked. See Sprint clarifies iPhone 4S unlocking policy on Macworld.
Sprint customer care representatives on its forums state that unlocking is done primarily for international use. Call Sprint World Wide on (888) 226-7212 to get it done.