How do professors learn how to write letters of recommendation?
As with most professorial duties, it's a sink-or-swim process.  There is no formal or official training they receive for this task.  They're just thrown into the situation with no experience and are expected to perform well at it immediately.  If they've seen other recommendations during their other duties (that they likely also weren't trained for) they can use that, otherwise they can try asking colleagues or do google searches.  So for the most part it's a bunch of untrained people relying on other untrained people and crossing their fingers that the other guys were able to figure out a good approach.