Imagine you're about to do 50 squats - after not exercising for months. Your muscles aren't used to the exercise, so you should expect to be sore. This soreness is called delayed onset muscle soreness, and it will be at its worse between 24 to 72 hours after the workout.
Delayed onset muscle soreness is thought to be caused by micro-trauma in the muscle fibers. Microscopic muscle tears occur when doing eccentric contractions, which is when your muscles contract and lengthen at the same time. Common exercises that cause eccentric contraction include lowering weights, push-ups, and the downward motion of squats. These movements involve your muscles sort of relaxing, but still contracting to hold the weight up. The tiny muscle tears cause inflammation, which activates nociceptors. Nociceptors are neurons responsible for sensing pain. As time passes, your muscles heal and the pain goes away. The once-sore muscles are also more adapted to the exercise and won't hurt as much the next tie they are put to work.
So, how are soreness and growth related? No one is really sure. While muscle building involves minor damage in healing, it's not clear if the soreness and growth use the same mechanism. Growing muscle has to do with lifting weights and dieting appropriately. So, from what we know, being sore has nothing to do with it.