There may have been a past traumatic experience that is causing your dog to be afraid of other dogs.
Dogs that are naturally submissive may also be fearful when encountering a more dominant dog.
If you are getting a puppy, be sure to ask about their socialization with other dogs including their littermates.