Like all human qualities - from genetics and training. Initially, a person's sensitivity to pain can be high or low, but like any physical characteristic, it can be moved in the right direction. Moreover, training is needed both physical and psychological. As they say, for 1 beaten 2 unbeaten give.
In addition, many medical parameters affect the pain threshold: women are able to endure long prolonged pain (as during childbirth), and men can more easily tolerate very strong, but short-term pain loads; with age, sensitivity is seriously reduced due to the death of nerve and vascular endings; some diseases and brain injuries directly deprive a person of pain.
Generally, at the genetic level, since pain as a sensation and its strength directly depend on the level of development of the peripheral nervous system.
Roughly speaking, the more sensitive your skin is, the more there is in individual pieces of the skin of nerve endings and, accordingly, the lower your pain threshold will be, since when exposed to many nodes, sensations will be stronger. Accordingly, it is possible to increase the pain threshold only due to the partial death of nerve cells, which occurs due to addiction to unpleasant sensations - in pseudo-scientific parlance, this sounds like "a change in the level of asthenic sensations through repeated stimulation."
This is how the fighters fill their fists - if you hammer hard objects for a long time and systematically, the joints lose their initial sensitivity and fragility, allowing them to use their hands as a working tool.