Some dishonest vet or vet tech is telling you a lie. If there is such a law, tell them to prove it. Of course, they cannot.
The ONLY thing required by law is that you vaccinate your dog for rabies, once every one to three years (depending on the state). Heartworm is not a zoonotic problem, so no legislature is going to create a law for something like this.
It is just a vet's office telling you that story. That person should be reported to the state veterinary license bureau and have his license suspended.
At the very least call around and talk to some reporters in your area.