This is a great question! I wondered about it myself.

It turns out that every time you have GPS turned on using an Android device, Google can detect how fast you’re moving. If a lot of devices indicate that traffic is moving slowly in a particular area then the conclusion is there is a traffic problem.

This information is shared to other Android users using GPS by indicating that traffic is slow in particular areas.