I guess it's because evolution doesn't work on individual organisms, but on genes.
Yes, it would be advantageous for the individual bird, upon observing a predator, to keep schtum and hide itself. The predator is much more likely to catch one of the bird's comapnions. If selection worked on individuals then they would all take the seemingly selfish route.
But the birds companions, the predators victims, are likely to have a similar genetic makeup. So that scenario still involves the loss of the same genes. And it would be much easier for the predator if each individual acts selfishly and doesn't warn its companions.
As a gentically similar population, the selfish birds would, possibly, not be as successful as a population that had the 'altruistic' gene for warning companions. So natural selection, working on populations, not individuals, could easily select for the observed beahavious.
In Meerkats, where a member of the family is posted as a lookout, a similar thing happens. But it has been observed that the lookout will only issue a warning one it has got itself to a relatively safe position. I wonder if the same thing does happen with birds.