When putting a deposit up when renting a house or apartment. The deposit is put up to ensure that the tenant leaves the property undamaged and clean.
If the property becomes damaged by the tenant or is left a mess then the deposit is kept by the landlord to do the repairs needed.
If you leave the house or apartment clean and undamaged then the deposit should be returned to you when your lease is up and you move out.