The play on words for literary effect is called a pun. A pun is a form of wordplay that exploits multiple meanings of a term or phrase, or the similarity of sound between two words with different meanings, for humorous or rhetorical effect. It is a type of figurative language that can add humor, wit, or cleverness to a text.
For example, "I'm reading a book on anti-gravity. It's impossible to put down!" In this pun, the word "put down" has two meanings, one of which is literal (to physically place something down) and the other is figurative (to stop reading or to criticize something harshly). The pun plays on the multiple meanings of the phrase to create a humorous effect.