Crookshanks was purchased by Hermione Granger from a store in Diagon Alley in 1993. The proprietor informed Hermione that he had been there for quite some time, and that "nobody wanted him." It could be that as a highly intelligent animal, Crookshanks was merely waiting for someone worthy of his companionship.
Crookshanks, Scabbers & Sirius Black
Crookshanks played an instrumental part in Sirius Black's attempts to enter Hogwarts Castle for the purpose of procuring Peter Pettigrew, who was masquerading Scabbers, Ron Weasley's pet rat. Crookshanks immediately took a dislike to Scabbers, trying to attack him through Ron's clothes the first time they met. Afterwards, Crookshanks independently sought Scabbers out, causing the rat to seek hiding places. When Scabbers took off to hide in Rubeus Hagrid's hut, Ron was convinced that Crookshanks had eaten him, causing a row with Hermione, until he was found at Hagrid's.
Crookshanks met Sirius Black in his Animagus form of Padfoot on the Hogwarts grounds several times, and stole the passwords to Gryffindor Tower from Neville Longbottom to help him get into the castle. Despite all this help, Pettigrew managed to escape capture and returned to the service of Lord Voldemort. After all this, Ron was able to accept Crookshanks as a remarkable animal companion.
Ron: "What was that?"
Harry: "It was either a very large cat or quite a small tiger."
— Ronald Weasley and Harry Potter see Crookshanks for the first time
Ron: "You bought that monster?"
Hermione: "He's gorgeous, isn't he?"
Ron: "Hermione, that thing nearly scalped me!"
— Hermione and Ron after the former's purchase of Crookshanks
"This cat isn't mad. He's the most intelligent of his kind I've ever met."
—Sirius Black on Crookshanks
All information taken from the Harry Potter Wiki.