I did something like that recently. A Captain in a flightsuit (RQ-4 guy, didn't know him) was leaving the building and halfway to the parking lot. No hat. You could tell from his expression/demeanor that he felt "caught", and had probably waited until the coast was clear. He sheepishly looks at me and salutes,... I return the salute, smile and say, "good afternoon!" while looking right at him, and continue inside.
There was no doubt that he simply couldn't find his hat.
There was no doubt that I recognized it.
There was no doubt he was going to fix it ASAP.
There was no doubt he appreciated that I didn't berate him on the obvious.
There are communication skills and techniques other than verbal. It appears that many in the USAF are weak in that area.
Now,... rather than discuss hats and sunglasses-on-the-forehead of officers, let's morph this discussion into why so many USAF Enlisted can't render a proper salute in a timely manner and with some military bearing, like the other military services can.