This line is said by Hamlet in Act III, scene iv. SPOILER ALERT for anyone who hasn’t read “Hamlet, Prince of Denmark” by William Shakespeare. This scene is one of the most crucial in the play, as it is where Hamlet has his moment and kills Polonius. This is his act of revenge, for all purposes, in the play, and now he must tell his mother that he has killed his uncle.
This line, for better or worse, shows how Hamlet has changed up to this point. He wanted revenge, so he put good behind him, acting “cruel to be kind” to his father’s memory. The second half of the line implies that there’s worse to come, and since this is only Act III, the readers and viewers would be inclined to agree with that.