There are actually two closely related expressions to disentangle here: cotton to and cotton on (or onto). The former means, as anongoodnurse points out in her answer, to like or take to. The latter can mean the same thing or it can mean to understand.
Thus, Dickens has Mr. Squeers use the idiom "cotton to" in discussing the special favor he had previously shown the runaway Smike (in Nicholas Nickleby, 1838–1839):
I have been that chap's classical, commercial, mathematical, philosophical, and trigonomical friend. My son—my only son, Wackford—has been his brother; Mrs. Squeers has been his mother, grandmother, aunt—ah! and I may say uncle, too, all in one. She never cottoned to any body, except them two engaging and delightful boys of yours, as she cottoned to this chap.
And Robert W. Service, The Trail of '98: A Northland Romance (1911), has this:
When they saw us they were hugely surprised. Ribwood was one of the party.
"Hello," he says roughly; "any more coming after you boys?"
"Don't see them," said the Prodigal breathlessly. "We spied you and cottoned on to what was up, so we made a fierce hike to get in on it. Gee, I'm all tuckered out."
An Ngram chart of "cottoned to" (red line) versus "cottoned on" (blue line) versus "cottoned onto" (green line) suggests that "cottoned on" became more common than "cottoned to" over the last 50 years of the period from 1800 to 2008:
I don't know whether that reflects a change in spoken usage of the two terms or not, however. Clearly, all three phrases remain in current written use.