HIV is short for Human Immunodeficiency Virus, so you're asking what causes the virus. Well, that doesn't make much sense and I don't think that's what you meant to ask. I think what you meant to ask is what causes AIDS, or Acquired Immune Deficiency Syndrome. AIDS is the disease that is caused by the HIV virus. You are correct that the means of contracting the disease such as unprotected sex is not the actual cause of the disease. That's only the way you become infected with the virus. It is the virus that causes AIDS, not the way you caught the virus in the first place.
A pretty good overview can be found here https://www.aids.gov/hiv-aids-basics/hiv-aids-101/what-is-hiv-aids/.