In broad terms, in a three pillar democracy, the job of the legislature is to make the law, the job of the executive is to enforce the law and the job of the courts is to interpret the law.
The courts may find that a piece of legislation is invalid, either in whole or in part for any number of reasons. The legislature can respond by:
- Repealing the legislation
- Changing the legislation to remove the invalidity
- Doing nothing.
Your first question is why would they go for option 3?
I can, off the cuff, think of several reasons:
- Time pressures, a legislature can only deal with so many pieces of legislation per year - it may not be a worthwhile investment of time to "tidy up" the statute books.
- Possibility of appeal, the precedent may be open to appeal or having an alternative ruling in a higher court.
- Precedent, unless and until the decision reaches the Supreme Court or equivalent then the decision is only binding on lower courts.
- Possibility of change to superordinate legislation, in the particular circumstance you cite, the local authority may leave the law on the books in the hope or expectation that the state law may be repealed or overturned - the local law would then be valid.
For your second question, the judge is supposed to know. That said, judges make mistakes so a wise plaintiff/defendant will draw the judge's attention to the current state of the law. It would certainly look bad for them on appeal if it emerged that they did know and allowed the judge to make a mistake. Firstly, they are officers of the court and secondly, justice is blind but justices may remember you made them look like a fool!
For your third question ... maybe. However, such a claim would be limited to what you actually lost through your lawyer's malpractice. It can't be the case because you couldn't win it anyway - the law was against you! You may be able to argue that the lawyer should be responsible for some of the costs or losses that arose from you failing to settle earlier. Good luck with that.