Part of the uniform....plus they were actually also part of some ground troops attire (Patton scolded his officers more than once about wearing their ties)
US, RAF, and other allies plus the European Axis pilots ALL usually wore a dress or other uniform that required a tie while waiting for sorties. As to wearing while flying, that usually came down to discipline and uniform standards from the units or squadron/bomb group CO.
Plenty of pics of pilots out there from all countries with ties on with their flight gear. Gotta remember that is only 20 years past WW1 where it was a but a gentlemen's game and prestige to be a pilot. Scarves (usually silk) were worn to not only protect the neck, but keep the neck warm. This tradition carried on to WW2. German prisoner of war camps for allied pilots were initially run or overseen by the Luftwaffe on Goerring's insistance. He had been a combat pilot in WW1 and though he was drug addict and had a sexual preference that should have had put him in a German concentration camp, he tried to see that Allied pilots were treated with that gentlemanly conduct while under the Luftwaffe officers oversight.
edit: I also remember reading somewhere years ago that ties made for good tourniquets for wounded flight crew.