If you have NOT changed your Trusted Phone Number, which is the number you receive two-factor authentication on when you sign in with your Apple ID, then you do not need to change the number, even if you have changed carrier. If you are still receiving messages on your number with your old carrier, it is because your number has not been transferred to your new carrier yet. The same number should not be active with two different carriers - but in that case you must contact them.
You can also check whether it is the right trusted number you have registered here:
Settings > Apple ID > Password and Security
Under trusted number, you can see your current number(s). If you need to add a number, tap Edit and follow the instructions on the screen.
You can find more information about 2FA here:
Two-factor authentication for Apple ID - Apple Support