That question is analogous to asking why did some fish grow legs and become mammals.
The answer is mutations sometimes specific members of a group will gain a mutation that will overtime cause that group to split off away from the ancestor group. It’s all a matter of chance evolution doesn’t have a direction.