Hockey became a sport of note in the middle of the 19th-century. Most of the players in these early games were rugby and association football players when there was not snow on the ground. In the cold winter months these fellas clamoured to the game of ice hockey, so they brought their soccer and rugby gear with them to the frozen ponds including the pants and the heavy wool shirts. For added warmth they put on a turtleneck and layers of sweaters. Thus the association of the sweater to the hockey game gear commenced.
Generally some layers of knee-high stockings were put on under the skates but to pad against impact and the cold weather. No one really cared to much if the uniform colors matched on one teammate to another, because generally there were only 14 players on a team and the opponents were local, common and repetitive. That all changed when teams started playing outside of their own towns and when roster sizes grew. When Seattle met Ottawa for the right to hold Lord Stanley's Cup, this similar colors thing became an issue as the two teams were adorned very similarly. The Ottawa squad stepped up to resolve the issue by donning white shirts thus a new tradition was hatched. By the time the 1940s rolled around many teams were voluntarily wearing contrasting sweaters to their opponents and in 1950 the NHL manadated the practice.
At first it was similar to the rule of thumb of football where the visitors wore white and the home team sported their dark colored tops. Then in 1970 Hockey Night in Canada suggested doing the polar opposite to allow the road team to show off their colors to a crowd that only saw them once every so often. This was a suggestion that had almost everything to do with a better color television broadcast than it did with what the home ice crowd would view.