Having been told this over and over again as a child there is a taboo that was set up about it. It's not right obviously. As a small child of course it is can be dangerous to talk to strangers but it is the worst kind of fear-mongering.
That's not to say that kids don't need to be protected and that there isn't caution to be had for small children. But the blanket statement "Don't talk to strangers!" tends to stick with people just like riding the bike on the wrong side of the road so you can see cars coming, because that's what they were told to do as children. In practice though even that is quite dangerous.
Clearly these both have benefits in their context but unfortunately there is no expiration date given for them.