There are a few reasons. First of all, your dog is trying to protect you and your home for someone he doesn't know. After all, the mail person does not come in the house and make friends with you or your dog. Which leads to another reason your dog barks: he gets a payoff for barking when the strange person approaches his territory and then leaves. Your dog feels he has succeeded in driving off the threat, he has been rewarded and reinforced for his behavior! Also, the mailperson is easy to predict. He or she comes at the same time each day, and your dog is alerted to their approach by the sound of other dogs in the neighborhood barking. For these reasons, teaching your dog not to bark at the mailman can be a challenge!
A dog that barks at the mail carrier is alerting you to potential danger. Teaching your dog that the mail person is not a threat will be the key to teaching your dog to stop barking at the mail carrier. It is natural for your dog to alert you to potential threats, to you, your home, and himself. The behavior you are after is to help your dog distinguish between what, and who, is and isn't a threat.
Your first step will be making sure that your dog is well socialized, regardless of their age. A dog that is predisposed to seek positive attention from other people can be taught who and what they need to alert to. Part of your training will be to specifically teach your dog the mail carrier is not a threat, which will often involve introducing your mailperson to your dog and creating a positive association.
In a rural community where everyone has large dogs, the dogs are loose to protect farms. Residents all have mailboxes at the end of their driveways. The local mail lady carried inexpensive treats with her whenever she delivered the mail. She would drop a few treats for the resident dog and soon she had even the most grumpy old farm dogs running down the driveway to her with tails wagging and taking treats eagerly from her hand, and none of them ever barked at her! In fact, the neighborhood dogs waited by their mailboxes at the same time each day, eager for her arrival. Most mail carriers are not going to go this far to create a positive relationship with your dog, so you will have to create the positive association instead.