It depends on the State but in most States I know of including California the carpet needs to be replaced every 10 years.
10 years is really the useful life of a carpet due to normal wear and tear so if you've lived in the apartment or rental home for 10 years then the carpet needs to be replaced.
If the carpet is under 10 years old then the cost to replace the carpet will fall on the tenant but if the carpet is 10 years old or older and needs replaced the costs will come out of the landlords pocket.