Deleting the eSim just removes your phone number and service plan. It has no effect on your other data or information whatsoever.
Also, if the iPhone is locked to a carrier, then it will not unlock it. Only the carrier it is locked to, can unlock it.
If what is locked is the eSIM, and is requesting a pin, then removing the eSIM will stop the pin requests. This, again, does not remove any of your info.
To remove your information and details, and get it ready for someone else to use, you must completely erase the iPhone, not just the eSim.
Follow the steps in the link below.
click here ➡️ What to do before you sell, give away, or trade in your iPhone or iPad - Apple Support
Once again, this will not unlock the iPhone if it’s locked to a specific carrier. It will still be locked to that carrier, and will require a SIM card from that carrier to get cellular service.
Of the iPhone is locked to a carrier, only the carrier it is locked to can unlock it. No other carrier can unlock it, nor can Apple unlock it either.
The carrier lock, and the SIM card lock are 2 different things.