occurs when a character’s words mean the opposite of their literal meaning.​

The literary device being referred to in this question is called "verbal irony".