The kind of a word (Wortart in German) and it's grammatical function are two different things that should not be confused.
The kind of a word is a property of a word, that it always has, even if it's not a part of sentence, for example when it's the heading of an entry in a dictionary. "Tree" is a noun, "fast" is an adjective, "eat" is a verb and "the" is an article. I can say this without building sentences using these words.
A word can only have a grammatical function when it's a part of a sentence or at least of a phrase. Standalone words are not embedded in any grammar, so they can't have any grammatical function.
Ich trinke meinen Kaffee gerne schwarz.
The German word "schwarz" is an adjective. This is the kind of word to which it belongs, no matter if this word stands in a sentence or if it's the heading of an entry in a dictionary (like Wiktionary, DWDS or Duden)
So, what is this word's grammatical function in this sentence?
Adjectives can be used in three different manners:
attributive
This means, it accompanies and modifies a noun, which means, that it appears together with this noun inside a nominal group:
Das schnelle Auto gehört meiner Tante.
The fast car belongs to my aunt.
Here the adjective "schnell" describes a property of the car.
predicative
Here you need a copula (a verb like sein, bleiben, werden) which can bind two nouns in nominative case to each other ("Hunde sind Tiere"), but copulas also can bind adjectives to subjects, and this is predicative usage of an adjective:
Das Auto ist schnell.
The car is fast.
Similar to the attributive usage the adjective "schnell" describes a property of the car, but it is not an attribute of the car. Instead it is bound to the subject (the word "car") via a copula.
adverbial
The third version looks very similar to the predicative usage, but the verb is not a copula, but any other verb. And this means, that the adjective is not bound to a noun. Instead it is bound to the verb itself. It is in fact an attribute of the verb:
Das Auto fährt schnell.
The car moves fast.
Here the adjective doesn't describe a property of the car. It instead describes how it moves.
The adverbial usage is not limited to verbs. Also participles and even other adjectives can be modified:
Dein kunstvoll gemachtes Kleid ist kräftig rot.
Your artfully made dress is bold red.
Here the adjectiv "kunstvoll" describes the participle "gemacht" and the adjective "kräftig" describes the adjective "rot".
So, what does this mean for your sentence?
The adjective "schwarz" is neither an attribute of the noun "Kaffee" nor is it bound to this noun with a copula like in these examples:
attributive: Ich trinke den schwarzen Kaffee.
predicative: Der Kaffe, den ich trinke, ist schwarz.
Instead the adjective "schwarz" describes the way how you drink it. It modifies the verb "trinken". And this means: It is used in an adverbial manner.
Well, on a semantic level it still describes a property of the coffee. This can be a little bit confusing. But we are not talking about semantics here. We are talking about grammar. And when we strictly focus on grammar, it is quite clear.
But be careful! That an adjective is used adverbial doesn't turn it into an adverb! Adverbs can only be uses adverbial, they can not be used as attributes or predicative:
wrong (attributive usage of an adverb): Dort drüben steht der ofte Bus.
wrong (predicative usage of an adverb): Der Bus, der dort drüben steht, ist oft.
correct (attributive usage of an adverb): Der Bus, der dort drüben steht, fährt oft.