This was a very common misconception at the time, based on a few factors like:
- Spike talking about his chip agonizing him before leaving for Africa;
- Spike talking about his goal with vague, angry phrases like "Bitch is going to see a change" and "Buffy [will] get what she deserves";
- Spike screaming in pain and what was interpreted as surprise when he's re-ensouled.
However, this was an intentional misdirection. This online essay is a great source on the matter, and contains some quotes from the show's creators explaining this twist:
Spike's quest was, and ALWAYS WAS, to get his soul restored for Buffy, despite any misleading leaks we may have put out that you fell for." -- [Buffy writer and producer] David Fury on the Bronze Beta, 11/19/02
Spike looked into his soul at that moment [the attempted rape], and saw the demon in him, and that's what made him want to go get a soul .... We did a big ole mislead on you all, where we wanted you to think he gonna go get the chip out. We knew, the whole time, from the very beginning he was gonna go get a soul. And when he says I want Buffy to have what she deserves, he means a lover with a soul. -- Jane Espenson, Buffy writer, radio interview on the Succubus Club, 5/22/02
Moderator: "At the end of the finale, I thought Spike wanted to get the chip out, not get his soul back?"
[Buffy creator] Joss Whedon: "Noooo.... but you were meant to think that. I personally devised something called 'a plot twist'." -- At the Academy of Television Arts and Sciences panel "Behind the Scenes of Buffy the Vampire Slayer", 6/18/02
And it almost fooled me at the time (his scream was especially confusing) until I stopped to think about his character arc after the episode and came to the right conclusion. He was always after his soul, and here are some choice bits from that essay in support of this:
If Spike wanted to hurt Buffy, he didn't need to get the chip out. It already didn't work on her. If Spike wanted to hurt Buffy's friends, he could have just hired some demons to do it. Unlike Angelus, Spike has never been interested in torture. [...]
Consider Spike's character: The decision to seek a soul was completely in character for Spike. Although he often ridiculed Angel's soulfulness, much of that ridicule came from envy. Angel, after all, captured the hearts of the two women Spike loved most more than Spike ever could.
Spike has always been portrayed as a character who would do anything for love, even give up evil. Even when he was dating Drusilla, he preferred loving her to committing evil (although he certainly loved both at the time). In Lie to Me, Spike's third appearance on the series, he chooses love over evil: he stops the massacre so that he can save Drusilla from Buffy. In Becoming, he goes so far as to help save the world so that he can get Drusilla back. Clearly, love is more important to him than evil.
...And it's completely within character for Spike, after fully coming to terms with his own monstrosity, to do something reckless for love.