Category differs from function because category denotes what a word is while function denotes what a word does.
What kind of [sentence] constituent is this? — This question denotes category.
What role does this [sentence] constituent perform? — This question denotes function. (Pullman, University of Edinburgh)
To go a step further, function is also one of the two word categories: lexical/content category and grammatical/function category. So while category denotes what a word is and function denotes what a word does, "function" is also one of two word categories (grammatical/ function category).
To clarify function/role more fully: The function (the role) of grammatical (grammatical/function category) words is to signify proximity, time, location, sequence and other relationships between lexical (lexical/content category) words.
Here's an example of function/role. First, we'll write a sentence with just lexical words: Cat sat mat. All the grammatical (grammatical/ function) words are missing. We'll add grammatical words: A cat sat by the mat. The cat sat on the mat. My cat sat nowhere near the mat. Each choice of grammatical words develops different relationships between the lexical words. This, then, is the function of grammatical/function category words: to build relationships.
In contrast, the function (the role) of lexical words is to signify who did what to whom (or what) where when how and why. For example: The cat jumped on the man in the yard in October by leaping over the fence in order to eat his fish. The function of lexical words is to signify the things, objects, or persons and the actions, states of being or events that are in relationship.
One final clarification of interchangeable terms that may confuse the category/function issue: Grammatical (function) words are parts of speech and are in a word class.
Grammatical words are parts of speech such as linking verbs (e.g., be) or prepositions (e.g., in, up) or articles (e.g., the) and are in the word class that is the closed word class, meaning there are no new additions to this word class: i.e., English has all the prepositions and conjunctions etc that we ever expect it to have. Contrast this to lexical (content) words that are parts of speech in the open word class for which new lexical words seem to be added daily: e.g., v. googling; n. biomarker.
Though clarity can be confused by similar or by interchangeable terms, category denotes the kind a word is while function denotes the role a word performs in a sentence: "Cat" is a lexical, open class kind of sentence constituent and is a noun that performs the role of Subject in a matrix (independent) clause noun phrase while, in contrast, "by" is a grammatical, closed class kind of sentence constituent and is a preposition that performs the role of head preposition signifying proximity in a prepositional phrase.