Before it was a state of mind, an obsession was a military operation.
The Latin verb obsidēre is built from ob-, "toward, facing, against," and sedēre, "to sit." To sit down facing a town was to occupy, blockade or besiege it. Merriam-Webster lists all of those senses, along with "beset" and "assail." The noun obsessio meant the act of besieging, a blockade.
Christian writers borrowed the picture. In Late Latin, the verb could describe a demon taking hold of a person. Middle English used be obsessed for being tormented by the Devil or an evil spirit. Merriam-Webster explains the metaphor plainly: the Devil's torment was compared to the siege of a fortress.
Theologians later made the siege image precise. The New Catholic Encyclopedia defines diabolical obsession as hostile action by the devil or an evil spirit "besetting anyone from without." Possession is the other case, where the spirit is understood to be inside. Merriam-Webster notes that possessed and possession sometimes appeared alongside obsessed in early modern English.
The verb had a quiet spell. From about 1660 to the early 1800s, obsess and obsession were very rare outside dictionaries. When it came back, it had lost its religious overtones, possibly under the influence of French obséder. Today it means to haunt or excessively preoccupy the mind.
The noun followed the same path from demons to psychology. Dictionary.com dates its first English record to between 1505 and 1515. Merriam-Webster gives 1680 as the first known use in its main modern sense: a persistent, disturbing preoccupation with an often unreasonable idea or feeling. Broader uses, like "an obsession with profits," grew from there.
The image never fully went away. An obsessive thought still behaves like an army camped outside the walls, always there, always pressing. The difference is that nobody now blames a demon for it.