Evolution is the change in animals due to environmental pressures. Where certain traits are useful for survival and reproduction, over the long term those traits come to dominate. So some locations select for tall and thin (the tribesmen on the plains of Kenya) and some select for shorter (pygmies in the Congo jungles).
The same as for the giraffe, for example - the taller ones had better foraging during the dry season - they could reach the higher leaves. Over time, they out-survived shorter ones. When you’re talking a million years, you can adapt quite a ways.
So each ecology has “niches” - an area food source etc. that is usable. If these is food going to waste, some animal will eventually find and exploit that food source, and then it’s a race to determine who is best suited. If some apes come out of the trees to exploit discarded lion kills that still have meat (protein) then the ones best able to run back to the trees will survive. The ones who can stand upright will see enemy approaching sooner, etc.
If a group eventually changes too much, they have trouble mating with a branch of the old group that has not had the same adaptions. So the ground dwellers don’t usually mate with tree-dwellers; their offspring would be not as good at either food source, by climbing or running. The animals drift apart.
We can see in the progression of sea otter, seal, whale the return to water was advantageous for some animals. If you eat fish, being able to chase it a ways into the sea helps; adaptations for sea make life on land less easy, so you stick to the shore. Etc.
Tigers are solitary hunters in the jungles, exploiting the larger jungle animals. Lions are, oddly, a herd-like cat family, adapted to chasing down the herd animals of the African plains.
The problem is, with every advantage comes a cost. Big animals (mammals) need more food just to stay alive. In times of scarcity, they get weak and die first. So there’s an optimum size for an animal in a niche, depending on supply and reliability of food source. really fast (like the cheetah) means you can run down your prey; but to win with speed you have no room for excess weight like fat reserves. Your range is limited to places with reliable food sources. A camel may have distinct disadvantages protecting itself against wolves, for example, compared to horse hooves or cattle horns. But in the desert, it can outlast most predators easily.
I read somewhere our brain consumes about 1/3 of the calories we need to stay alive. So it better provide a significant advantage in our survival. Obviously, for a few million years it has.
Small monkeys live in jungle trees and eat fruit. Madagascar had no such animals; millions of years ago, some lemurs must have survived being washed out to sea to Madagascar. Now they occupy that niche, and many others on that island. Places like New Zealand, or Mauritius, with no natural predators giant birds evolved to be flightless grazers. Adding humans, cats, or foxes to the islands created a predator they had no time to adapt against, and they either disappeared or are close.
Evolution is nature seizing an opportunity. Animals best suited for the opportunity will exploit it, and any offspring even better adapted will dominate that opportunity, and so on.
Crocs and cockroaches have not changed in tens of millions of years because their niche has remained the same, and no animal has arrived that could exploit that niche better. Where food sources disappear for months at a time, like the Nile, cold-blooded has a distinct food advantage over warm-blooded who need a feed daily. Cold-blooded is less of a disadvantage in the tropical water than on dry land where temperture fluctuations could leave a cold-blooded animal vulnerable while cold and sluggish. (Most reptiles nowadays are either water-based or hide themselves at night).