Which figure of speech is used in this text?
I must be cruel, only to be kind:
Thus bad begins and worse remains behind.
—William Shakespeare, Hamlet

 - euphemism
 - paradox
The text uses a paradox, a statement that might at first appear to be contradictory, but that may in fact contain some truth.
Be cruel, only to be kind at first appears to be contradictory, as cruelty and kindness are opposites. However, it contains some truth: being cruel to someone in the short term may benefit him or her in the long term.