Yes.I want to know if (legally) I can keep their deposit.
You can legally retain monies from the security deposit to cover rent that should have been paid to you up to the end of the notice period that should have been given by your tenants.
Whether or not you should do so is a separate question.
Many landlords would simply return the security deposit in full in these circumstances and would focus their energy on re-letting the property as soon as possible, using a letting agent where appropriate.