The relationship between pain and extasy has confused and equally excited for time eternal, from that first moment when physical pleasure was derived from a most unexpected and unwelcome source, to the oft occasions when phycological torment is inclined to make an individual or situation increase in seemingly undeniable attractiveness.
The easiest and most acceptable reasoning for the physical pain/pleasure connection is the nature of existence itself. All life activity, beyond the safe but limited comfort of the swaddling cloth, must necessarily carry some risk of negative discomfort, hurt and suffering. The world we inhabit is after all amok with sharp objects to scratch, graze and cut, unpleasant flora and fauna to inflict distress through one means or another, and any other panoply of uncontrollables guaranteed to bring anatomical discomfort unexpectedly and unavoidably. Life is unquestionably dangerous from the moment we rise to the time we return to our cot, and even then sanctuary cannot be assured. The ability to smile through mild hurt, to perhaps accept graciously, almost gratefully, minor discomfort is the only way such continuous severe peril can be weighted and mollified.
The question of psychological adversity perversely increasing desire or need is, I am inclined to consider, far deeper and more perplexing. We all have experienced this phenomena in one form or another, or if that admission is too hard to own then can recognize others so afflicted in the past or present. People are in general inclined to live in a fantasy world, where situations, relationships, interactions have as much to do with what is possible, is desirable, is personally acceptable, as to what is real. This is particularly true when these perceived ideal changes, suddenly or incrementally, when acceptance of the new reality would overwrite or even obliterate the imagined perfection. The inclination is then to either dissociate, ignore, obfuscate, or in extremis dilute and become amorphous. Humanity was after all gifted with opposing thumbs and finds letting go incredibly difficult.