No disrespect to Mulrooney, but the matter needs a little expansion .... and, btw, I have issues with a few other assertions others have made:
First off, ANYTHING can happen in court. The 'good book' makes this point repeatedly, in warning us to avoid courts at all costs. Just because "I saw it happen" does not mean the judge was correct.
A court cannot / will not / should not enforce an illegal contract. That's why (non-casino) gambling debts are not collectible through the courts - nor are drug deals, prostitution agreements .... OR contracts made by unlicensed contractors. That's one of the ways the laws are enforced. That said, judges are no fools, and will often find a way to act when they feel someone is 'finessing' the system.
Liens are wonderful things, but the specifics vary greatly from place to place. Most important are the differences in the required notice and time constraints. Perhaps that's why both jurisdictions where I hold licenses featured lien questions on their tests.
Judges can't "make" someone pay? Excuse me? "Making" folks do things they don't want to do is exactly the business judges are in. OK, they can't "make YOU," but they can send the constable to seize your assets and distribute tham as HE sees fit, and they can send you to prison. Your cheerful co-operation is not required; if necessary they'll have the marshall "help" you along. Early in WW2, there was a very famous news picture of marshalls physically carrying the head of Montgomery Ward out of his office, still on his chair. Don't tell me the judge can't "make" you do things.
That all aside, the lack of a permit does not, IMO, void a contract. It may be grounds for a complaint against you with the contractors' board, and the jurisdiction may assess other penalties for your not having one ... but voiding the contract is not one of them. If the town orders the work stopped, the customer is still responsible for the work already performed. Who's responsible for paying permit fees is a separate matter. Likewise, inspection activities may result in the contractor suffering losses.