In the Medieval days they used to raise their eye shield when wearing armor. Then later it was to show they had nothing in their hand. It’s a sign of respect to a higher officer.
I also assume that when men wore hats, they removed their hats and bowed to a superior. Later that became just touching the brim of the hat; and from there, it evolved into various hand movements related to the same.
Who should return the salute, showing mutual respect. That is a key part of it as well.