Situational irony is when information is hidden from the audience and other characters in the story. In Richard Cory, both the townspeople and the audience are unaware of how unhappy Richard Cory is until he takes his own life. The audience experiences the situation through the townspeople's perspective. The townspeople are jealous of Richard Cory because he seems to have everything. They don't realize that despire his wealth and prosperity he is unsatisfied with life. When the speaker very bluntly says that he put a bullet through his head, it is shocking to the audience and townspeople, creating situational irony.
In situational irony, an event occurs that directly contradicts expectations.
This contradiction lies in the perspective of the townspeople with regard to Richard Cory. In descriptions of Richard Cory, it becomes clear that the residents of the town perceive him as greatly elevated from them in social and economic class. First of all, he does not live where they do. The narrators are "on the pavement"; that is, they dwell in the heart of the city. Their main occupations are centered in the city where the jobs used to be for the men. There, too, women care for their families at home, or they work as servants for the wealthy like Mr. Cory. But, during the Depression of 1893, the setting of this poem, many people are out of work. This is why they "went without the meat, and cursed the bread," their main form of subsistence.
As one of the upper class, Richard Cory does not suffer as do the citizens of the town. He is "richer than a king" and "imperially slim," not starved as they are. Therefore, because of their dire poverty during the Depression, the citizens feel completely estranged from Richard Cory, perceiving him only as a typical member of the wealthy class, except for the fact that he speaks to people. Nevertheless, they misinterpret his "good morning" as simply an example of how he is "schooled in every grace" rather than his genuine desire to communicate with others because of his wealthy isolation.
The (situational) irony, of course, is that the common people misinterpret Richard Cory's demeanor and speech. Convinced that Cory is happy because he suffers no financial want and he is handsome, so much so that he "flutter[s] pulses" when he speaks and "glitters" as he walks, they are shocked when, "one calm summer night" Richard Cory commits suicide. This act of despair does not fit with their perceptions and expectations of such a wealthy gentleman, at all.
Please see the link below for another answer.