The answer to this is likely to be different for different people. Some people might do it because they are coerced, others because they are sure they will not get HIV, while still others because they do not care. People often do things that are very risky even when such actions seem utterly irrational.
Some people might engage in risky sexual behaviors because they feel they have no choice. This is likely true of many women in Africa and of many prostitutes in all countries. Women may feel coerced by their husbands. Prostitutes may be forced to engage in risky behavior by pimps or by traffickers.
Some people, particularly young people, act in risky ways because they do not believe that they will be harmed. People often believe that bad things only happen to other people. Therefore, they (in this case) engage in risky sexual behavior because they feel invincible. They would rather give in to the excitement of the moment because they think there is no real risk.
Finally, some people might engage in such actions because they do not feel that it matters. They may feel that their lives are not that valuable. They may care more about having excitement than about the consequences.
Thus, there are many different reasons why people would engage in behaviors that put them at risk of contracting HIV.