Jason's correct that you should have been given some explanation. I can think of a number of reasons:
1) The tenant gave adequate notice and left in accordance with their lease terms. You tried to deduct the next month's rent from their deposit. As long as they left in accordance with the lease, the time it takes you to do your make ready is not their problem. A judge would take a very dim view of trying to charge rent after they left.
2) You have a time line for returning the deposit or providing an accounting? For me, that's 30 days after they turn over the unit. If I don't provide a written accounting and their money (if any), then I MUST return the entire deposit. Actually, the tenant is allowed to require triple damages, and I could be required to pay them triple their deposit.
3) You tried to charge them to replace the entire carpet. Maybe the judge felt like after five years the carpet was "normal wear and tear". Now, I would personally disagree. If the carpet was in good condition and was clean before they moved in, they should have returned it in the same condition. But if you couldn't document when the carpet was installed or when you last cleaned it, the judge may have assumed the carpet was 20 years old and you were just trying to make the tenants pay for a replacement that was due anyway.
Impossible for any of us to say, given what you wrote. But there are any number of reasons why the tenant may have been due the money.
Some things, like periodic replacement of carpets and lost rent due to make ready time, are just part of this business.