Mostly landlords have made a fixed deposit of the security deposit that they took from you.Now they can't break their FD because it is fixed for a tenure(5+ years)So they'll ask you to get another tenant and take the security deposit that you submitted from them. Now this is actually the best way to get your 100% security deposit back, because usually if you take your security deposit back from the owner they would deduct a lot of charges and you'll be getting around 60% - 70% of your security deposit.It's a win win for both the parties.Legal or illegal should depend on how rental agreement has been made, so you should have a look at it.