Rental Deposits Refund

I have realized that a lot of people are having a hard time getting their Deposits Refunded by their previous landlords. My question is,Is a deposit a payment for any service or is it just some kind of a Goodwill?? Secondly do the landlords have any right to hold back Deposits? Third and last question do we have any set of rules either an act or in the constitution that gives the amount of time a tenant is supposed to notify the landlord of their intention to leave their premises?? I have a friend who is trying to pursue 45k deposit cash but the Agency is not willing to refund the money. Any help will be greatly appreciated.

Usisumbuane na mtu akurudishie 45k, lipa vijana wa odi pesa kidogo kama 3k, wafanye kazi yao, upate pesa in 24 hours. ii kenya hapana bembeleza mtu, yeye hakubembelezi, anataka akuibie mchana, mbona ubembeleze punda kwa mteremko?