There are several different types of irony, and authors may employ them for different reasons. Verbal irony refers to the use of a word or phrase to mean the opposite of its usual meaning, and it may be included in fiction to either add an element of humor or build characterization by showing the discrepancy between a character's words and intentions.
Another type of irony, dramatic irony, occurs when the reader is aware of something that a character is unaware of. This type of irony was commonly used in Greek tragedy, and it allows the author to build anticipation in the audience. Dramatic irony can illustrate the effects of misunderstandings or betrayal on a character before that character is even aware of their situation.
Lastly, situational irony refers to a situation that includes contradictions or an unexpected outcome. An author may employ this type of irony in order to subvert expectations in the plot and add plot twists.