Gamma Spectroscopy: 511 keV peak?
A true annihilation peak at $E = 511\ \mathrm{keV}$ is caused by the detection of individual annihilation photons. The source of such annihilation photons can be:

1) Pair production in the surrounding material caused by high-energy gamma radiation
If the gamma energy is large enough to make pair production in the surrounding material (typically in the high-$Z$ shielding material surrounding the detector) relevant, the gamma quantum (a high-energy photon) may disappear and be replaced by an electron and a positron. The electron and positron may travel a few millimetres before losing their kinetic energy to the absorbing medium. When its kinetic energy becomes low, the positron may combine with an electron in the absorbing medium. Then both disappear and are replaced by two annihilation photons of $E = 511\ \mathrm{keV}$ each.

2) Positron emission of the source
If the source consists of a radionuclide that decays by positron emission (β+ decay), and the positron is stopped and undergoes annihilation before it reaches the detector (i.e. the positron is stopped within the source volume or in the material that is encapsulating the source), this region acts as a source of annihilation photons of $E = 511\ \mathrm{keV}$ each.

If one annihilation photon reaches the detector and is absorbed within the detector, an annihilation peak appears in the spectrum at an energy of $E = 511\ \mathrm{keV}$.

Furthermore, a peak at $E = 511\ \mathrm{keV}$ could be caused by mere coincidence due to

1) Coincidence summing
If two gamma rays are detected approximately at the same time, the spectrum will show only one count at the sum of their gamma energies. If the sum amounts to approximately $E = 511\ \mathrm{keV}$, the resulting peak would look like an annihilation peak.

2) Double escape
If the gamma energy is large enough to make pair production in the detector material relevant, the photon may disappear and be replaced by an electron and a positron. The electron and positron may travel a few millimetres within the detector before losing their kinetic energy and finally combining with an electron. Then both disappear and are replaced by two annihilation photons. If one annihilation photon escapes from the detector without interaction within the detector, a single escape peak appears in the spectrum at an energy of $511\ \mathrm{keV}$ below the full-energy peak. If both annihilation photons escape, a double escape peak appears at an energy of $1.02\ \mathrm{MeV}$ below the full-energy peak.
If the remaining energy is approximately $E = 511\ \mathrm{keV}$, the resulting escape peak would look like an annihilation peak. This effect is not possible for single escape peaks since their energies are always well above $E = 511\ \mathrm{keV}$, but it is theoretically possible for double escape peaks.