Sade faced several different allegations of criminal sexual conduct and was imprisoned in the Bastille by his mother in law via a special letter from the king. It should be noted that he had an affair with his wife’s ten years younger sister, who wrote him love letters written in blood.
While in the Bastille he writes to his wife complaining that every night he throws up everything he’s eaten in the day and that he does not sleep at all and has been denied his camp bed. He repeatedly says he’s never been in a worse state and begs his wife to get him out. There are claims he threatened or even attempted suicide at points during his captivity. It was from this mindset that he wrote 120 Days of Sodom in prison.
Libertine novels were being written all over Europe at this point in history, notably Dangerous Liaisons and The Indiscreet Jewels, though perhaps none so shocking and extreme as 120 Days of Sodom.
The Libertine movement as a whole was dedicated not just to sexual freedom but to complete liberation of human desire from every religious, societal, and even moral consideration. Libertinism is often mentioned in relation to hedonism, but with additional focus on physical pleasure and a deeper philosophical opposition to societal, social, and particularly religious norms.
At this point, the wider culture of France was becoming more anti-establishment, anti-clerical, and democratic as the French Revolution approached. Sade is recorded as having yelled accusations of cruelty done to the prisoners out of his Bastille cell’s window to crowds gathering below in the time leading up to the storming of the Bastille, which eventually led to his being moved and losing the manuscript of 120 Days of Sodom.