The City Code requirements are an implied part of every contract. The contractor breached his contract by failing to get the city permit and the HOA approval. Once you gave the contractor an opportunity to correct the situation and he refused, you had a right to terminate the contract and hire another contractor. You should dispute the debt and consult with an attorney. You may have an action to recover the monies you paid the contractor.
The attorney may require a retainer for the court costs, deposition costs and other out-of-pocket costs that he may incur to handle your case. Only his attorneys fees are contingent. If however you have a very good case for a substantial sum of money, you might be able to convince an attorney to front the court costs. You would still remain liable and they would be deducted from your eventual settlement.