Though Pico dela Mirandola’s text has the virtue of being early, the primary text of the history and science of sadomasochism is A Treatise on the Use of Flogging in Medicine and Venery by Johann Heinrich Meibom (aka John Henry Meibomius), 1590-1655. Meibom published his treatise in 1639, and it was still being referenced more than 200 years later when people tried to explain masochism.
I finally found an online copy of the complete text in English, an edition published in Paris in 1898. It’s a dense read, but interesting in several respects.
Meibom cites several examples that sexual masochism does exist, but then dismisses the arguments that this is a result of astrological influences (as Mirandola did) or local custom. He proceeds to establish a mechanistic, physiological explanation, that the loins or reins are related to the male reproductive capacity, and in certain men, especially older ones, arousal and ejaculation depends on excess mechanical stimulus to the loins.
Meibom has no psychological theory, and particularly no theological theory, for masochism. The sex act and its aberrations are purely physiological events, in keeping with the materialist philosophy of the Enlightenment. God, sin, penance or mortification of the flesh has no part in it.
Three centuries after Christianity effectively banned mortification of the flesh from lay religious practice, voluntary flagellation still exists and is viewed in completely secular terms.