It's derived from the precursors of the verb hängen ('to hang'), apparently during Late Middle High German times (15th century). Thus, it's also related to the Low German verb hangen which has been around since Middle Lower German (13th--16th century).
spätmittelhochdeutsch hanc = Neigung, zu hängen
Late Middle High German hanc = tendency to hang
DWDS has a extensive etymological entry for hängen, which has its roots in Old High German hāhan and hangēn (intransitive) ('to hang', both 8th century), and further gives this information for Hang:
‘Neigung, Geneigtsein, hängende Stellung (des Turners), abschüssige Stelle’ (15. Jh.)
Inclination, proneness, hanging pose (of a gymnast), precipitous location (15th century)
stating the same time of origin.