Landlords may make deductions from a tenant's security deposit, provided they do it correctly and for an allowable reason. Many states require landlords to provide a written itemized accounting of deductions for unpaid rent and for repairs for damages and necessary cleaning that exceed normal wear and tear, together with payment for any deposit balance.
The deadlines vary from state to state, but landlords usually have a set amount of time in which to return deposits, usually 14 to 30 days after the tenant moves out -- either voluntarily or by eviction. (See Nolo's Chart: Deadline for Returning Security Deposits, State-by-State.)
(If your landlord is withholding your security deposit, see Nolo's article Get Your Security Deposit Back.)