"Humanity must learn Esperanto."
Translation:La homaro devas lerni Esperanton.
I would say "la homaro".
"Homaro devas lerni Esperanton" I would interpret as "A humanity" or "A group of people" (one of many) must learn Esperanto, but if you mean the one single humanity, the one that you are thinking of and that you expect me to know about, I would use "la homaro" because it seems definite to me, even if English doesn't use the definite article there.
Basically, very infrequently. Imagine a fictional setting where many similar groups of human-like species exist across several planets - one could then make some general statements, perhaps, about "a humanity" in general (e.g., homaro nur estas tiel bona kiel sia moralo). It might be appropriate to say homaro in real-world philosophical questions as well, where we consider the factors that gave rise to humanity as we know it and compare them to all theoretically possible worlds and outcomes.