Unlocking a phone generally does not void the manufacturer's warranty, even if the phone is unlocked before a service contract expires. However, unlocking a phone may violate the terms of service of a cell phone service contract depending on how the unlocking procedure is performed.
Unlocking cell phones is legal as of 2015, and many cell phone service providers do provide unlock codes for phones on request. However, service providers often mandate that a user only unlock a certain number of phones within a 12-month period, or that the phone has been active for a certain period on their network before it is unlocked. Unlocking a phone through a third party may violate these requirements and potentially incur fees or termination of the service contract.