I couldn't find that regulation and looking at wikipedia regulations about that are country specific:
https://en.wikipedia.org/wiki/SIM_lock#European_Union
It seems sim locking is legal, but unlocking has to be allowed after some time.
I couldn't see anything that would differentiate between a carrier lock by esim vs a sim.