Dr. Justin Lehmiller answers the question “Why do men have nipples?” on his Sex & Psychology blog:
For the first six weeks that we’re in the womb, we exist in a gender neutral state, regardless of the chromosomes we carry. This means that each of us starts with the same set of bodily structures, which have the potential to develop toward either the male or female form depending upon what our genes and hormones direct them to do later on. It is during this neutral stage that the nipples begin to develop, which makes them a permanent structure that everyone is going to have for life, whether they are genetically male or female. The difference, of course, is that if you’re a genetic female, you will eventually develop breasts, whereas if you’re a genetic male, you won’t.