It's called syllepsis, although that word, ironically, has several different meanings.
One type of syllepsis is syntactical; that is, a word is used in a sentence so that it has a literal meaning with one part of the sentence, and a figurative meaning with the other part: