That random mutation didn't happen, basically.
Evolution is a purely subtractive process. It doesn't design things in, it just removes poorly-designed creatures (and all hypothetical offspring) until only things equipped to survive are left. And obviously, there are things to eat that aren't grass.
Edit: Herbivores can be smart, even the grazers. Look at elephants.
I can't believe how many other replies heap that fallacy on top of teleological evolution. Apes are mostly herbivorous anyway, WTF.