This is a common problem that occurs when debris (wax, oils, skin flakes) gets inside the battery case and accumulates around the battery contacts.
Below is a photo of one of two battery contacts inside a common hearing aid. Each contact must lightly "scratch" the battery when the door is closed to make a good connection. If your hearing aid goes dead intermittantly the contacts may be dirty from wax, skin cells, and oils. Carefully use a pipe cleaner, an old typewriter eraser, or a thinned and narrowed Q-Tip (very lightly moistened with rubbing alchohol or amonia) to clean the contacts. Make sure the contact is dry before replacing the battery.