Your bulb is loose. Usually that's all it is.
A bulb gets power from two spots. The little dot on the bottom touches a flat metal tab inside the socket. The threads on the side touch the metal shell. If either one isn't touching properly, the bulb goes dim or cuts out until you nudge it back into place.
There are only a few reasons this happens, and they're easy to tell apart.
The bulb isn't screwed in all the way. This is the most common one, and it's usually the bulb you just changed. Give it another quarter turn. If it stops, that was it.
The tab inside the socket has been pushed down. Older sockets have a flat metal tab in the middle. Every bulb you screw in presses on it. After enough bulbs it stays bent down and stops reaching the bulb. That's when tapping the fixture brings it back for a second.
The contacts are dirty or dull. Kitchens and bathrooms are the worst for this. Look at the dot on the bottom of the bulb and the tab in the socket. If either one is black or crusty, that's your problem.
One more thing people miss. Some bulbs look like they fit and don't. The threads match and it screws in fine, but the base is a different depth, so the bottom never actually touches the tab. You end up with a bulb that looks seated and does nothing. If a brand new bulb won't light in a socket where the old one worked, try another bulb before blaming the socket.
How to check, without getting zapped. Switch it off at the wall first. Take the bulb out. Look at the tab in the middle of the socket. Is it sitting up, or flattened down? Then look at the bottom of the bulb. Is the dot clean and silver, or black?
Wiping the contacts with a cloth is fine. Bending that tab back up is not something I'd do with the power on, and on most small night lights you can't reach it anyway. If the tab is flattened, the thing is usually finished. Replace it instead of fighting with it.
If any of this comes with heat, a plastic smell, or a burnt look, stop. That's not a loose bulb, that's something worse.
Anyone else had one that needed a tap to wake up? What turned out to be the problem?