What is the name of the device used when an author uses the same word to different effects in a sentence. Here, the word 'good' is used as both a noun and adjective e.g. 'and good goods swimming in the water' - Samuel Pepys
This is a kind of antanaclasis.
As defined by the OED, antanaclasis is
A figure of speech involving repetition of a word in a different sense.
A famous example is "Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo."
However, antanaclasis is not limited to using the same word multiple times as different parts of speech. So while "good goods" involves "good" used as both a noun and adjective, it qualifies as antanaclasis, but phrases also qualify when they use different senses of a word in the same part of speech.
For example, from Shakespeare's Henry V:
"To England will I steal, and there I'll steal"
This phrase uses two different senses of the word "steal," but in both cases they are verbs.