Imperfect replication, competition and LOTS of time. Whenever I contemplate how something got to be that way I always come back to considering the span of time. We can easily envision the passage of a hundred yrs. maybe even a thousand. But 10,000? or 100,000 yrs?
Just a mind-numbingly slow accumulation of useful bits.
You have to remember that natural selection (and therefore brain evolution) stopped in humans thousands of years ago,
What about the next big asteroid or if Yellowstone blows again? What about the next plague or massive crop failures? I don't think that you measure much evolution in terms of thousands of years.