How do professors and lecturers learn to teach?
This answer is based on my experience in Germany, and in an engineering field.
For interested teachers, universities usually have a central department that offers training, workshops, brochures, and plenty of information about how to teach. For example, here, here, and here.
Many lecturers do not take advantage of these possibilities and still learn on the fly. Doctoral students often have recently attended master courses and observed how teaching was done there. In many cases, the professor gives the lectures and the doctoral student teaches the corresponding tutorial, which consists of doing practice exercises on the board. This is easier to do than teaching concepts, and provides an opportunity for the doctoral student to become confident in teaching.
Evaluation by the students also plays a role. The students are asked to give anonymous feedback on the lectures and tutorials approximately at the middle of the semester. The teacher can then learn what they can improve in their method of teaching.
[US/R1-specific] Although faculty usually have recourse to some sort of university teaching resource center that can provide videotaping, training, professional evaluation, etc., it is rarely the case that either research or instructional faculty are required to engage in teaching development activities. My impression is that those who become genuinely good teachers are (1) talented and (2) take the initiative to educate themselves about the research. But this seems to be a rather small minority--most faculty apparently come up with their own pedagogical beliefs and practices based on their personal experience.
Some copy what they saw from their lecturers - hopefully only the best bits of course.
Styles of delivery - spacing of materials, topics etc
Types of assessments and combinations of continuous assessments with exam(s)...
Some do a teacher training course - some places offer a level for schools, others a level for higher and further education. And I can still lay my hands on my reference number for my teaching qualification.
Met some who make excellent teachers without training and others that should not be allowed near a classroom even after training...