I spent money to pay the legal service fee and get the rent, I would like to deduct the legal fee from the deposit that the tenant gave me when he move out. could I do this?
Absolutely not. Even assuming your lease provides for prevailing party attorneys' fees, these are generally awarded in an instance of litigation. A security deposit can only be held for damages beyond normal wear and tear and unpaid rent. If you withhold a mediation fee as part of a security deposit-- which is not an attorney's fee -- then you could be liable for up to 3x that amount. Courts do not look kindly upon landlords who improperly withhold security deposits.
If you have to sue the tenant for unpaid rent, and if you have a written lease that allows you to collect attorneys' fees, then claim them in any lawsuit you bring.
DISCLAIMER: Brandy A. Peeples is licensed to practice law in the State of Maryland. This answer is being provided for informational purposes only and the laws of your jurisdiction may differ. This answer based on general legal principles and is not intended for the purpose of providing specific legal advice or opinions. Under no circumstances does this answer constitute the establishment of an attorney-client relationship. For legal advice relating to your specific situation, I strongly urge you to consult with an attorney in your area. NO COMMUNICATIONS WITH ME ARE TO BE CONSTRUED AS ARISING FROM AN ATTORNEY-CLIENT RELATIONSHIP AND NO ATTORNEY-CLIENT RELATIONSHIP WILL BE ESTABLISHED WITH ME UNLESS I HAVE EXPRESSLY AGREED TO UNDERTAKE YOUR REPRESENTATION, WHICH INCLUDES THE EXECUTION OF A WRITTEN AGREEMENT OF RETAINER.