That transfer usually shows up as a credit on the statement of adjustments a lawyer prepares before possession, alongside prorated rent and any utility adjustments, so the buyer effectively receives the deposit dollar for dollar rather than the seller keeping it and the buyer starting a new one.
The seller's lawyer and the buyer's lawyer coordinate this as part of the closing file, the same $800 to $1,500 legal work that handles the mortgage discharge and title transfer through Information Services Corporation, so nothing about the deposit needs a separate side agreement between landlord and tenant.
A seller with a tenant in place should confirm the exact deposit figure and any interest owed before listing, since that number becomes part of the deal. Get your hand-reviewed valuation from Joel Dyck.