What is this rubber thing on my gear cable and what does it do?
Such rubber rings are supposed to keep gear and brake cables from rubbing against frame tubes. That is, when the cables are mounted openly outside the frame.
There are three rubber rings, also known as "cable donuts" in your picture. With a little effort you can separate them and space them out along the cable. As gschenk says, they are supposed to prevent rubbing or slapping damage to paint or decals and prevent cable slapping noise.
They get mixed reviews.