Like many Asian and African countries, India was under British rule during Kipling's lifetime. Colonialism was a major economic and political factor in establishing the role of Britain as a world power. And it was a subject of great interest to the upper classes in Britain. Colonial India offered Kipling a context in which to examine the relationship between the British rulers and the people they ruled.
We have reason to believe that Kipling was in favor of colonialism. However, he may have used this provocative setting to explore subtleties about power, superiority, and colonialism, especially by presenting the story from the viewpoint of Kim, who was British by birth but lived among the Indians.
India is also an excellent place to set a story for a young reader. A faraway country is an intriguing place to set stories of mystery, adventure, and unusual experiences.