First, your cousin would need to perform all of the steps in this support document:
What to do before you sell, give away, or trade in your iPhone or iPad - Apple Support
As the owner of the phone and account, he would need to contact Xfinity and ask them to unlock the phone. They may be under no obligation to do this, even if the phone is paid off. It all depends on his plan agreement with Xfinity.
When all of the steps in the support document have been completed and the phone has been unlocked by Xfinity......then and only then would you want to pay any money for the phone.
You will know that all of the steps have been completed because the phone will display the "hello" screen. If it doesn't.....do not buy the phone.....it has not been fully unlocked from the owners Apple ID and Password because the seller forgot this information......or the phone is not really his or hers.
It would be up to you to set up the phone and contact T-Mobile to ask them to send you a SIM card for the phone, or you could probably have this done at a T-Mobile outlet.
The All Too Common SAD Reality of Buying a Used iPad/iPhoneAppleOfficial Apple Support Community › docs › DOC-250001038