My answer will specifically address American use of hearing protection, as that is what I am familiar with. I will break my answer into two parts, WWI and WWII.
World War I:
During WWI soldiers did not use hearing protection. The leading theory at the time was that you would develop a tolerance to noise from being exposed to it. In fact, wearing hearing protection was seen as cowardly.
World War II:
From 1939 to 1941 the tolerance theory was still the leading theory on hearing loss, and the protocol was largely the same as it was during WWI.
During 1941 the US Army called for a study to be done on the matter. At this time there was some recommendation from the US Army on wearing hearing protection, but there was no requirement. I cannot find any information about the availability of hearing protection to soldiers at that time.
The study that started in 1941 finished in 1944, and it was at that time the US Army officially recommended all gunmen wear hearing protection. Again, this was a recommendation, not a requirement. It was at this time that we see references to soldiers using earplugs to protect their hearing.
Here is an article from the US Department of Public Health on the matter.