Is it legal to unlock a phone?

Unlocking your phone with or without a contract at doctorSIM is completely legal and your carrier will never penalise you for unlocking your device.

Phone unlocking and contract commitments are independent of each other. 

The commitment to a contract is tied to the service, not the device. Unlocking it will allow you to use it with any carrier, although the contract will remain in effect until it is canceled or terminated.

In the event of not fulfilling the contract, the carrier could block the device by IMEI blocking.

Such blocks are additional and independent of doctorSIM's service, and can only be removed by the original company.

The same applies in cases where the phone does not belong to the account holder due to being second-hand. It's important to ensure that everything is in order with the original carrier.

This block could be carried out after the unlocking process, even if it is valid, because carriers review pending cases periodically.

If you're wondering whether unlocking a phone can void the warranty, rest assured that you have nothing to worry about. You can read more at Does unlocking the phone void the warranty?