TW: Self harm/injury, suicide
Let’s get this out of the way first: not all people who self harm or self injure are suicidal.
Life Signs UK differentiates between self harm and self injury: they state that self injury is a type of self harm, in which physical pain is purposely inflicted on oneself as a way to feel physical pain, often as a coping mechanism for emotional pain: It is easier for some people to feel physical pain than it is to express emotional pain.  By the Life Signs UK definition, self injury is deliberate infliction of pain that is not suicidal.  They also define self harm as anything that is causing harm to a person’s body: eating disorders, risk-taking behaviours, drug and alcohol abuse, and self-injury all fall under the umbrella term of self harm. 
Why do people self harm?
Many people who self-harm have deep emotional pain or trauma.  Often they do not know how to cope with problems or life pressures. Eventually, negative feelings not dealt with can build up and become unbearable, and results in self-harm. If you are feeling like self harm is your only option, people can help you find other ways to cope: call a helpline. If you are feeling suicidal, call 911 or go to an emergency room. Google for a self injury helpline in your country. In the US call 1-800-DONTCUT (366-8288) or visit SelfInjury.com or To Write Love on Her Arms.
Sometimes, it may be caused by other mental health issues or be linked to dissociation, but often it is not and is a coping mechanism or response to pain, including loneliness, isolation, stress, frustration, or anger. 
Some people with intellectual disabilities may be more likely to self-harm. 
Who self harms?
“Self harm can affect anyone.”  It is not tied to genetics or background or personality type. Some people self-harm for a short period of time or in response to a certain problem, and then never do again. Others may self-harm for a long period of time.
UK research states girls and young women, adolescents between 15 and 25, people who are institutionalized (including prisoners, those in residential care, etc.), people who identify as LGBT*+, and those with addictions are more likely to self harm. 
Several issues may lead to self injurious behaviour. These include body image problems, low-self esteem, being bullied or discriminated against, sexuality or sexual identity concerns, cultural or racial problems or experiences of racism, all types of abuse, grief/bereavement, loss or adjustment such as parental divorce, work or money problems, addiction, relationship problems, knowing someone who self harms or who has died by suicide, those facing unplanned pregnancy, not having strong emotional connections or feeling rejected by important people in your life such as parents, and people living with chronic or serious illnesses.  If you have a chronic illness, having social or emotional support is as important as taking medicine and wearing medical ID is to stay safe and be as healthy as possible.
Managing self injury
Having support and learning coping strategies will help people to avoid self harm and self injury. This resource from Mind UK helps people to stop self-injury in the short term.
Mind also has a guide for how to deal with stopping self-injury in the long term. If you are struggling, speak with a doctor or mental health resource in your community for where to go for support.
Most of us know someone who has self harmed, either now or in the past. Understanding the reasons why people may self harm can help us to be more compassionate to those around us, or to ourselves if we are struggling. If you are struggling, help exists. If your problems are real to you, they are real: do not minimize them and continue to experience pain. Reach out and get the support you need.