The officer is provoked by the mob into shooting the elephant because he feels he must do so in order to avoid displaying weakness as a member of the ruling class.
After a call comes in about a rogue elephant, a crowd has formed by the time Orwell arrives with a rifle he only brings to defend himself if necessary. He begins to feel foolish with the "ever-growing army" of Burmese following behind him, jostling one another for position. When he spots the elephant, he sees it does not notice of the crowd, but continues to pull bunches of grass calmly, beat them against his knees to knock out the dirt, and then stuff them in his mouth. Looking at this elephant contentedly eating, Orwell "knew with perfect certainty that I ought not to shoot him."
Because of the crowd, which has grown to nearly two thousand to watch him "as they would a conjurer about to perform a trick," Officer Orwell feels baited by the crowd. At this moment, Orwell has a sudden realization about the burden of colonialism:
The white man turns tyrant, it is his own freedom that he destroys. . . it is the condition of his rule that he shall spend his life in trying to impress the "natives," and so in every crisis he has got to do what the "natives" expect of him.
Therefore, in his compromised position, Orwell feels compelled to shoot the elephant "solely to avoid looking like a fool."