The first words that Hamlet speaks (either in an aside to himself or directly to his uncle, are:
A little more than kin and less than kind.
This is a play on words because Claudius has just referred to him as his cousin and his son and the quick-witted Prince disputes the inference of familial affection. (Cousin had a less precise denotation then).
Hamlet is saying that his kinship with the new King is closer than he would like in the sense of family: Claudius is now a father, being married to his mother, as well as his uncle in the normal way. Yet Claudius is not kind to him in the sense of being well-disposed.
It is a pun because the two words are connected in derivation and, from what we can surmise about a late Elizabethan audience, they would have relished the clever but bitter phrase. It is neatly alliterative also with an added contrast between more and less. Yet Hamlet does not use but, perhaps because he needs to link the opposition closely: he has to tolerate the paradox as a whole.
The root term for both words in Old English meant species, a sense we still have when we say two of a kind. The connection is that to be kind one must act as a relative or kin should behave, in gentle and friendly fashion.
We still say kith and kin where kith refers to acquaintances and kin to family. Another interesting point is how reactions to puns differ now from then. We groan at them whereas they admired them: this assertion is to be (or not to be) discussed over a CUPPA.