While a dirty or corroded terminal could be the cause, most likely it was a loose terminal. If the terminal got that hot the cable probably needs to be replaced for some distance from the melted terminal, that is, don't put a new terminal on the old cable end. The battery or a charging
device or a heavy use of the battery would not cause a terminal to melt. The battery would go first if the battery got that hot - expand and burst, explode, etc.
Also, make sure the terminal always is put the first thing down at the battery with any washers on top of the terminal. Stainless steel
washers are not good conductors of electricity and can get very hot if between the terminal and the battery. Stainless steel
is okay for this use - on top.