The story
From anal + retentive. First use appears c. 1936 in the writings of Marjorie Brierley. From the Freudian concept of the anal stage (roughly synonymous with toddlerhood), according to which children who are strictly punished for episodes of (especially fecal) incontinence during toilet-training eventually learn to retain forcefully their excreta, in order to avoid punishment; as a result, they develop ultimately in life a strong distaste for any kind of mess, disorder, imperfection, or lack of control. Compare anal-expulsive, which is the opposite extreme.
Etymology from Wiktionary, CC BY-SA 4.0.