When a character's words mean the opposite of their literal meaning, it is referred to as irony, specifically verbal irony. This literary device is often used to convey a meaning that contrasts with the literal interpretation of the words.
For example, if a character looks out at a rainy, stormy day and says, "What lovely weather we're having!" this statement is an example of verbal irony because the literal meaning is positive, while the intended meaning is negative or sarcastic.
Verbal irony can serve various purposes, such as adding humor, highlighting a discrepancy between appearance and reality, or emphasizing a character's feelings or attitudes.