Answer:
The thrushes were allies of the people of Dale and the dwarves of the mountain since olden times. The thrush overhears what Bilbo has to say about his trip in to meet Smaug, including the location of the dragon's weak point. Having heard this, the bird decides (apparently based on a sarcastic suggestion made by Bilbo) to fly down to Esgaroth and to alert Bard to the location of the wyrm's weak spot.
From "Inside Information":
But the hobbit was worried and uncomfortable, and they had difficulty in getting anything out of him. On thinking things over he was now regretting some of the things he had said to the dragon, and was not eager to repeat them. The old thrush was sitting on a rock near by with his head cocked on one side, listening to all that was said. It shows what an ill temper Bilbo was in: he picked up a stone and threw it at the thrush, which merely fluttered aside and came back.