Children experiment and practice. They produce sounds and then listen to their own sounds as well as those produced by others around them.
Part of this experiment and practice is the stage of language development referred to as babbling. During babbling, infants work towards producing sounds specific to the language they've been exposed to and gradually develop more and more sophisticated sounds that still (mostly) lack meaning. Infants select and repeat those sounds they make that replicate the language they hear from others.
Periods during development when certain skills are learned preferentially are called critical periods. There are early critical periods in language development after which it is more difficult (but not impossible!) to learn to pronounce new syllables because the practice/experimentation phase is passed.
de Boysson-Bardies, B., & Vihman, M. M. (1991). Adaptation to language: Evidence from babbling and first words in four languages. Language, 67(2), 297-319.
Hallé, P. A., De Boysson-Bardies, B., & Vihman, M. M. (1991). Beginnings of prosodic organization: Intonation and duration patterns of disyllables produced by Japanese and French infants. Language and speech, 34(4), 299-318.
Oller, D. K., Wieman, L. A., Doyle, W. J., & Ross, C. (1976). Infant babbling and speech. Journal of child Language, 3(1), 1-11.