In The Moon Is a Harsh Mistress, is it ever specified why/how Mike (HOLMES IV) achieved self-awareness?
(Since Mike also figures in "The Cat Who Walks Through Walls", the answer may come from either of those sources, or any other Heinlein canon).
I think the only explanation given is that when Mike has the same number of "neuristers" as a human brain has neurons, he wakes up.
They kept hooking hardware into him ... Human brain has around ten-to-the-tenth neurons. By third year Mike had better than one and a half times that number of neuristors. And woke up.
Somewhere along evolutionary chain from macromolecule to human brain self-awareness crept in. Psychologists assert it happens automatically whenever a brain acquires certain very high number of associational paths. Can't see it matters whether paths are protein or platinum.
The Moon Is a Harsh Mistress, p. 7 (Ace paperback edition?)
There you go: "Psychologists assert."
You find a probable explanation in Heinlein's other novel, Time Enough for Love. In short, this says that for a computer to become self-aware, some other people have to treat that computer as a real person, just like you would treat a child: you'd talk to him like you'd talk to an adult, even if he doesn't yet understand all of it. It is this interest that makes them self-aware.
Now Time Enough for Love is most likely not in the same universe as The Moon is a Harsh Mistress, yet I think this explanation matches nicely. It was very likely that Mannie has treated Mike before his wake with the same respect as you can see in the beginning of the novel.
I think Mike himself comments that he became self aware when an upgrade increased his total computing capacity beyond the capacity of a human brain.
I don't have the book anymore so I can't quote the exact line.