Dogs that were bred to herd instinctively perform this behavior, humans don't train them, they primarily encourage it. Many of the best pet dogs were originally bred for herding because it's counter productive to have an aggressive dog working livestock. Herding dogs are generally more intelligent, more tolerant and less likely to bite viciously (not always, but generally speaking).
Usually instinctive (as opposed to trained) herding is with uh, living things (children, ducks, cattle, other dogs) but most of the shelties in this country have been bred for aesthetics so you get a little cross wiring. Consequently, they try to herd anything that looks similar that's moving, ergo, leaves.