Are types of phrase named after the elements from which they are constructed or after their grammatical function?
There are different systems for describing grammar, so many concepts can be described with various terms depending on which system of terminology you're using. Sometimes it is more useful to refer to the components of a phrase, and sometimes it is more useful to refer to its function, so systems tend to have labels for both composition and function.
"In the river" is classified as a prepositional phrase, regardless of its function, in all systems of terminology that I am familiar with. The label "prepositional phrase" corresponds to the categorization of the word in as a preposition.
Some systems of terminology use the term "adverbial" to categorize the function of a phrase. In these systems, "in the river" in the sentence "They swam in the river" would be both adverbial in function, and a prepositional phrase in form. It doesn't stop being categorized as a prepositional phrase just because it is categorized as "adverbial". For further information on the meaning of "adverbial" and how it differs from "adverb", see the answers to this Linguistics SE question: Is the adverbial phrase and adverb phrase identical?
Other systems of terminology may refer to this function with another term like "verb phrase adjunct". Whatever you call it, an "adverbial phrase" is not the same kind of category as a "prepositional phrase", so it doesn't make sense to ask whether a phrase is one or the other: it might be both.
The answer is both.
Phrases are called after the head of their constituent elements. In such an analysis your sample is clearly a prepositional phrase (definition below). When discussing the meaningful units within the clause -- the sentence phrases -- the terminology used is noun phrases, verb phrases, and their component parts -- where, for instance, in addition to the verb, a verb phrase may also include a prepositional phrase.
On the other hand, when looking at the syntactic functions of clause elements, the terminology used is 'subject, verb (predicator), object, complement, adverbial'. An adverbial (from Dictionary) is
a word or phrase functioning as an adverb
In your example "in the river" is a prepositional phrase functioning as an adverb, i.e. an adverbial.
Here's a link (there are many others) which equates prepositional phrase with adverbials or adjectivals.
Prepositional phrases (adverbials/adjectivals)
These are formed from the head, followed by a noun phrase. Examples of prepositional phrases are in the teapot, on the toilet, and round the bend. They may be called adverbials since their usual function is to qualify a verb in the same way as an adverb does. You can test this by replacing a given prepositional phrase with an adverb - for example: Fred swam in the river and Fred swam swiftly. Both of these are grammatically standard forms. They may also function as adjectives: the pirate with the wooden leg.
So your sample can be called a prepositional phrase or an adverbial depending on the terminology you are using.