Guitar buzzes when you take your hand off the strings
Every conductive component in an electric guitar needs to be earthed at a common point (usually to the back of a pot), including the strings.
One of the most common causes of an irritating earthing buzz can occur when the guitar’s bridge isn’t earthed properly. To find your earth wire, look inside your control cavity for a wire that disappears into the body (on a Les Paul-style guitar) or is attached to the bridge/vibrato.
Bad soldering, botched modifications or just bad luck can mean that sometimes this wire gets dislodged, and when you touch your guitar strings, you earth the guitar, and the buzzing stops. Check out the wire and reattach it if it’s come off. If there’s no obvious detachment, replace the wire.