The homeowner certainly had the right to use the gun in this instance. It doesn't negate the fact that it is illegal for him to possess the gun, or the fact that it is entirely constitutional for the citizens of Wilmette to pass the law making it illegal to possess the gun.
A bad or stupid law is not necessarily an unconstitutional one.