The deposit is to cover any costs the tenant cause the landlord. Damage and unpaid rent are both costs.
A tenant who has $1,000 in upaid rent and $0 is damage is no different than a tenant who has $1,000 in damage and no unpaid rent. The security deposit can be used to cover either.