It sounds like the phone has Find My iPhone/Activation Lock enabled. You'll need to reach out to your friend (assuming he/she was the previous owner) and have them remove the phone from Find My iPhone before you can sign in with your own Apple ID.
There are comprehensive steps in this article for you to provide to the previous owner - Turn off Find My iPhone Activation Lock
Any time you purchase or obtain an iPhone, it is important to know or have contact with the original owner in case they forgot to turn off Find My iPhone.
If the previous owner is not your friend and/or you have no method of reaching that person, the phone will remain locked and you will not be able to use it with your Apple ID. This is a security feature, so neither Apple Support or the Apple Store will be able to assist.