You need to unlock your phone when you are moving from one network to another. Example- You are currently on O2 and moving to EE and you aren’t having a new phone.
If your phone is locked there are several forms online you can fill in to get the network to unlock your phone:
Vodafone- https://www.vodafone.co.uk/vodafone-uk/forms/unlock-code-request/
If you have a personal account, you should be able to log onto your online portal and request them to unlock.
You can also call your network and ask them to do this for you.