Different metals when in contact with each other in the presence of a solvent or electrolyte (water is considered the universal solvent - impurities in water can make it an electrolyte, and, given enough time, nearly anything is soluable - might take eons, though!) can act as a battery. Batteries wear out when the chemical action lets the two (or more) components reach an equilibrium. The resulting compound is usually not very strong and can become more soluable and wash away in the process. When this occurs in piping, the junction fails.
The way around this is to use all of the same components, or use a "moderator" in between that is less reactive with each of the offending components. If chosen correctly, the resulting electrolytic action is slowed so that it isn't a problem for the normal service life of the items