How to delete photo on iPhone but keep them in the iCloud library?

I'm giving away my iPhone to my mom, before i erase my phone i wonder if i do so would the pictures on my phone vanish from iCloud library as well?

Photos of iPhone and iCloud are connected to each other. So even if keep the photos in iCloud, those may still be accessible from the iPhone that you're going to give to your mom.
Rather you can use Leo privacy guard app and hide the photos from your iPhone, so that it is safe from your mother.