You might find the answer in this thread: https://www.reddit.com/r/AskHistorians/comments/3xi11m/why_is_it_traditional_to_remove_your_hat_out_of/
... as well as this article: http://www.penelopejcorfield.co.uk/PDF's/CorfieldPdf8_Hats.pdf