Look at this link
remove the lamp ensure the bulb is the correct type if recently replaced ensure the bulb is securely seated and the connection is clean and clear of corrosion. Perhaps change the bulb seeing as you have the lamp removed.
I have the same problem as do many others. Behind a Green 2003 beetle, when brake lights come on, the right one goes out. Only when headlights are on.
Had it to VW repair five times out of warranty now, no fix. help