Soldiers used wipe their snotty faces in their sleeves. The sleeves would be encrusted with mucus and (often) blood after just a day in the field, which made them look awful. The idea of putting buttons on the sleeves to prevent this is attributed to both Napoleon and Frederick the Great of Prussia. Since Frederick ruled fifty years before Napoleon, he was the more likely inventor.
Now, trying to figure out why modern men wear neckties was a lot more complicated, and there are many more theories about that, none convincing enough for me to regurgitate it here. In general, the first images of ties are seen on some Roman statues. However, the Croatians are credited mostly for the modern necktie.