Yes there is a penalty to pay if you break the lease contract by returning it before the completion date. Same as a car. It may be that they simply continue the lease payments to the end of the contract, or the contract may have some kind not-quite-so-bad penalty that was negotiated to sweeten the deal for the airline to get the deal in the first place.
The airline will do a business case and balance the penalty costs of breaking the lease early against the losses of continuing to run their unwanted behemoth to the end of the lease contract and proceed based on the cheaper option. Even if they have to keep making lease payments to the end of the contract, it still may be worthwhile to return the aircraft and escape from maintenance and insurance costs, if the aircraft was killing them financially, which is what this sort of thing suggests.