The safest way to buy an iPhone is to purchase through Apple of an authorized dealer. Apple sells refurbished phones at reduced prices in its online store.
If you purchase from an individual, make sure they have followed these instructions to prepare for new user...
What to do before you sell, give away, or trade in your iPhone, iPad, or iPod touch - Apple Support
I would not buy any phone, unless the seller can illustrate that he has properly cleared the phone. We see too many people here on the forums who have unknowingly bought phones that are still locked to another account. They will never be able to use these phones!