they can tell due to the hormones / pheromones given off , same as they can tell when the female is on heat etc
they often become protective the same as they would in the wild with any mother-to-be within a pack
its a natural animal instinct and is present in humans although we have lost the ability to use it quite a lot due to evolution
i studied breeding programs in cattle and animal behaviour for a few years !