From wikipedia: "The definite article is used to refer to a particular member of a group or class. It may be something that the speaker has already mentioned or it may be something uniquely specified."
For example: "The Queen of England hosted a reception." Here, I have not previously mentioned any particular queen of England, but I can still use the definite article because the currently reigning Queen of England is unique and almost any listener would already know who she is.
It is in this sense of "something uniquely specified" that the definite article can be used with an entire category of something. As you say, it can be used with nationalities: "The Germans reunified in 1989." Here the thing that is being uniquely identified is the set of all German citizens - I don't have to "previously mention" the existence of the set of all German citizens because the listener and I already know what the set of all German citizens is.
This isn't limited to just people. Any time you use a noun that refers to a well-known unique object or a well-defined complete classification of something, you can use the definite article:
Protect yourself from the sun. [The sun is unique.]
The stock markets fell overnight. [Which stock markets? All stock markets.]
The dinosaurs became extinct millions of years ago. [Which dinosaurs? All of them.]
The mercury in a thermometer expands with rising temperature. [Which mercury? Any mercury that's in any thermometer.]
The historians do not like that I don't use historical terms. [Which historians? Any historian who reads my writing.]