While “The Man Who Would Be King” is, on the surface, an entertaining story about two ineffectual con artists taking over a foreign land, it is also an allegory about British colonialism. While Kipling was a proponent of British colonialism, he took issue with some of the ways that the British government was ruling India. He believed that colonization must come from a place of moral authority—of desiring to improve the quality of life of colonized subjects by “civilizing” them—rather than from controlling and exploiting them for personal or financial gain.
In this way, "The Man Who Would Be King” is an allegory for the parts of British colonialism (particularly in India) that Kipling was against. That Dravot and Carnehan get the idea for colonizing Kafiristan while living in colonial India—and that they pick a country with a majority Hindu population—effectively sets up a parallel between the two contexts. It becomes clear over the course of the story that Dravot and Carnehan represent the British government and Kafiristan becomes a stand-in for India. It is notable that both men start their colonial project with what Kipling would consider to be good intentions, as they give up alcohol and women (or act morally) in order to prioritize bringing technological advancement, education, and positive relationships to the people of Kafiristan.
As Dravot shifts from ruling Kafiristan from a place of morality to ruling from a place of greed, the allegory's political message becomes more clear. Here Dravot comes to represent what the British government could become if it lost its moral authority and became increasingly comfortable using violence against the Indian people and exploiting its resources (and women) to benefit themselves.