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.