As Jane mentioned... this could just be 'who he is' and have NOTHING to do with previous experiences. There are a lot of shady breeders out there who breed dogs that shouldn't be bred. Unfortunately, it's not uncommon to see fear aggressive shepherds. You can work with the behavior. It can improve. However, he *may* be a dog that's never totally comfortable with strangers and may always need to me monitored and managed. I think right now you have an important decision to make. Are you willing and able to deal with this behavior if it continues long term to one degree or another? Are you willing and able to pay for trainers, behaviorists, or whatever it takes and take him to classes and learn how to help manage the behaviors? It's not easy. Anyone who says it is, is feeding you a line. If this is your first dog, or your first shepherd, I'd think long and hard about it. Shepherds are a WONDERFUL breed. However, they've been exploited by people who don't care. This is often the result. Even a 5 month old who hasn't been overly socialized shouldn't be this way. So I have serious doubts that it's just a matter of socialization.
The worst part is, the people who sold/gave the dog to you HAD to know he acted this way. To place this type of pup in a home with a child and not say a word about these issues is beyond irresponsible.
OTOH, I think you should have realized when the pup reacted that way in the home that something was 'off'... which leads me to believe this is your first GSD (at least, as an adult). To have this kind of issue with your first shepherd is more that what the 'average' person can deal with. GSDs that don't have behavioral issues are 'more dog' than the average dog.
It's possible that something happened to make the dog fearful. That doesn't mean it's going to be an easier road than if it's all genetics. You have a 5 month old puppy that's growling and barking at people. He's afraid. He feels like he's got to handle these fearful situations himself because he's not bonded to you yet... he doesn't trust you to take care of it. This dog is going to get bigger and more powerful. At some point (left to his own devices) he may decide to lash out at what he's afraid of. That is ALWAYS a possibility in a fear aggressive dog.
You need to learn a lot of language and definitions if you're going to keep and work with this pup. Things like "thresholds", "reactivity", "desensitizing" and "LAT" to name a few. Please, do some reading. Talk to some trainers right away. Look realistically at how much time you have to dedicate to this dog. Lastly, if you decide not to keep the dog, have him neutered BEFORE you re-home!! This is a dog that should not be bred. I have a nearly 7 month old male... just to give you a comparison. People he doesn't know can come into my home. He doesn't run and hide, he doesn't bark, he doesn't growl. He greets people nicely. Even in a strange place. Your pup is not being protective. It's not acting 'normally'. Any way you slice it, this pup is going to be a LOT of work. You may see great progress, you may see minimal progress. No one can say. Obedience classes are going to be a MUST. You have to have total control over a dog like this. You have to learn to 'read' this dog to avoid him biting someone and to avoid going over his threshold. It sounds like the class you took him to was way over his threshold. I would have not taken him there. At the very least, I'd have left with him when he first started showing signs of going over his threshold. When you keep him in that situation where he's afraid, and he sees no way to get away from what he's afraid of, the chance that he'll bite increases greatly. It's the 'fight or flight' and it sounds like this dog lives in this zone whenever strangers are around.
I wish you the best, and please keep updating. Also, go read the 'aggression' area of this forum. It will give you some clue as to what you may be facing, as well as suggestions as to how to deal with it, etc.