Not entirely sure how this works, but I think the medical retirement means player is paid for the reminder of the contract but that amount doesn't count on the club's cap.
If a player just decides to retire mid-contract, without 'medical retirement', then the contract is finished by mutual consent. Player doesn't have to play and club doesn't pay, and the rest of the contract amount no longer counts on the cap.
Of course clubs have been suspected of 'encouraging' some players to retire, with some off-the-books inducement (allegedly) precisely because of the salary cap relief. (Josh Jackson springs to mind)