Electrical contacts use pressure to maintain contact between two points. No different than a device like a flashlight which uses a bent metal tab or coil spring to make contact to the battery on one end, something to maintain pressure. Two flat surface even if they were exposed may wear or flex or somehow distort over time and would lose contact. I imagine it also accounts for any normal variation in manufacturing. So long as one of the two points of contact is spring loaded, it can flex and press back making up for any difference in height or length. It's not the only way to make contact, but it's the most effective for temporary electrical connections involving removable objects vs a more permanent connection like screws (car battery cables, home wiring). There are so many small precise points of contact between a cpu and motherboard, pins are probably the most effective, reliable and cost efficient method.
Even if there were a better design to get the job done from an engineering standpoint a large factor for real world applications is a balance between function and cost efficiency. If one method is much faster and cheaper at a slight expense of function from the end user's viewpoint, that will be the preferred method used by a manufacturer. Time is money and more parts able to be made per hour equates to efficiency and profit.