The tradition of two people tipping their hat as a sign of respect is something we are all familiar, even if we do not actively observe this tradition today. We have all seen historical movies where the characters are frequently seen removing their hats as a sign of respect to each other.
These days we are more likely to show acknowledgment and respect with a simple reciprocal nod of the head or by touching the brim of our hats. It is believed this is the origin of the salute as touching the hat brim became a more formalised hand gesture in the military. (source)
The origin of the hat tip dates back to medieval times when knights would raise their visors as a signal that they had no malice intent. This practice evolved into the practice of hat tipping.
Historically this tradition only applied to men, with women not following this practice. Men would remove their hats completely when showing recognition to women but a touch of the hat brim was often regarded as sufficient between men.
A sign of friendly intent
The formality of men removing their hats when entering churches and when inside also is thought to date back to the practice of knights removing their helmets when inside. This may also explain why women are not expected to remove hats when inside in the same way that men are.
Hats as status
These traditions were more prominent in an age when almost everyone wore a hat. Wearing a hat was a sign of status with the upper class wearing top hats and lower classes wearing flat hats. With the hat almost being a uniform of status the hat tipping went hand in hand with this ubiquitous accessory. This also explains why hat tipping and saluting are still prominent in the military.
Why hat tipping has declined
Over time people on mass have stopped wearing formal hats. Casual and practical hats are far more common, if any hat is worn at all. While hats are fashion accessories they are rarely linked to status as before. The decline in formal hat use probably explains why the once common practice of hat tipping is now less common. The more subtle nod to show respect has also replaced the more overt hat tip in this context.
Cowboy hat etiquette still calls for hat tipping and it is not uncommon to see people marking respect by touching their hand to their hat. So, despite the decline in use the hat tip is still universally recognised and a sure fire way to show respect when done in a subtle way.