Carpet should be replaced in between tenants if there has been a pet or smoker in the apartment. If neither of those has happened, the carpet should be inspected after a tenant moves out. The minimum care should be steam cleaning the carpet before a new tenant moves in. If any questions exist, replace the carpet.
There are no "carpet replacement laws." A property must be safe, livable and not cause health problems. To this end, the carpets should be cleaned but there is no requirement to replace them. Let your feet do the talking and find another place to rent.
Usually a landlord can tell if the stains cannot be taken out of the carpet before it should be cleaned or replaced. He should let the tenant know prior to signing the lease what the cost per sq. yard would be. He can pro rate the cost based on age of carpet. This should also be part of the lease.