What is the purpose served by cicadas in anime? Why do so many anime (e.g. Code Geass, Steins; Gate, Ano Hana) have cicadas in the background?
In Japan, cicadas are symbolic of summer, and possibly symbolize reincarnation as well, based on summer being the time when the cicada comes out to sing.[1]

As per their role in anime, according to Wikipedia,

The songs of the cicada are often used in Japanese film and television to indicate the scene is taking place in the summer.
  — Cicada, Wikipedia

I do not remember when exactly they appeared in Steins;Gate (nor the other anime), but I would assume that this is simply a reference to a summertime setting.