Earthworms are not insects, but annelids. They are beneficial organisms because they break down organic matter. Their tunneling aerates the soil and reduces compaction. Of the four types of beneficial organisms (predators, parasitoids, pollinators and recyclers), earthworms are considered the kings of recyclers.
However, on very rare occasions, earthworms can become pests in home lawns. For example, in an area just north of Houston, Texas they became so numerous they disrupt turfgrass areas, leaving them spongy and littered with earthworm castings.
Earthworm castings. Photo by Bart Drees.