What year and model is the car? In the taillights the bulb ha a socket that it sits into which then connects into the taillight housing. Their should be a plastic cover that comes off easily in the trunk for each of the tail lights. Remove it and then you will see the black sockets protruding out from the light assembly. Turn them a quarter turn to remove them. Inspect the bulb and see of it is loose. Inspect the socket and see if it is loose in the assembly. I had to replace two of them for my brake lights because they were loose. They were only like $10-15 at the dealership.
For my 1998 328i it's part # 63-21-1-387-365 E36 Lamp Socket.