I believe this stems from Funakoshi Sensei to be honest. In 1924, Funakoshi Sensei implemented the Dan/kyu rank system. He was personal friends of Kano Jigoro Sensei and asked if he could use the system, Kano Jigoro Sensei gave his permission. This was to satisfy several Japanese requirements placed on Funakoshi Sensei i.e. establish a rank structure, uniform etc. Remember, at his time in history, Japan was extremely Imperialistic and martial. Ranks structures were ingrained in the society so it follows that it would be so in Karate as well. Competitions may have played a very small part of the requirement, but it would have been implemented regardless of competition or not. So originally at least, it was more a societal thing than ego (though ego plays a part in many things we do, including rank).
And if we're honest, ego still plays a part. If not, people would care about the color of their belt and/or number of stripes. They would be content to let their skill and/or knowledge speak for itself. Same in a competition venue, you really don't need colored belts to match people of comparative skill levels. That is taken care of during registration. Same in a school setting, students pretty much know who-is-who. I suppose I'm a bit of a throw-back on this (and many other) points. Like I mentioned, I haven't worn a belt since 2005 and even before then it was spotty at best. Same with the students. They knew who I was and I, like a good instructor, knew who they were and what level they were at.