Hemicolectomy is primarily performed to treat colon cancer, particularly when the cancer is localized to one segment of the colon. The surgery aims to remove the cancerous cells and prevent the spread of the disease. It may also be performed for other conditions such as inflammatory bowel disease or diverticulitis, but its primary indication in the context of cancer is the removal of malignant tumors.