From the day the buyer gets title, the new owner is responsible for returning the security deposit. The new owner must give each tenant a signed statement confirming the purchase, the new owner's responsibility for the deposit, and the exact dollar amount. As the seller, you remain responsible for deposits you collected until the new owner receives them or takes over that responsibility, unless your written contract says otherwise.
Put the deposit amount and handoff in the closing discussion. Keep the lease and deposit records with the sale documents so the transfer is clear.