Can I use an eSIM on a locked iPhone?

No. The iPhone must be carrier-unlocked to use another provider's eSIM. To check, go to Settings → General → About and look for Carrier Lock: it says "No SIM restrictions" when the phone is unlocked. If it's locked, ask your carrier to unlock it before you travel.