Follow these instructions:
Restore your iPhone, iPad, or iPod to factory settings - Apple Support
Your friend should proably have done that before giving it to you. If they didn't log out of Find My iPhone, you may have a problem.
What to do before you sell or give away your iPhone, iPad, or iPod touch - Apple Support