David Feldman, in his book Imponderables, addresses the question. Quoting:
"The association of colors with babies undoubtedly started as an attempt to identify the gender of that one group of humans to whom the cliche ‘they all look alike’ often applies.
"But why blue for boys? In ancient times, it was believed that evil spirits lingered over nurseries and that certain colors possessed the capability to combat evil. Blue was considered the most powerful color, possibly because of its association with the sky and thus, heavenly spirits. Since boys were then considered the most valuable natural resource to parents, blue clothing was a cheap form of insurance.
“Evil spirits apparently couldn’t bother with pestering baby girls. Not only were girls not dressed in blue, but they had no color to call their own until centuries later. Our association of pink with girls stems from European legend, which professed that baby girls were born inside of pink roses…[and] that baby boys were born in blue cabbage patches…”
Feldman isn’t always as concise as one would wish, and he’s nowhere as comprehensive or funny as Cecil, but he’s usually got high accuracy marks for what he does say.