You are right, In general, the etiquette is to return hand salute if head-cover (peak cap, beret) is on. However, there are exceptions sometimes.
In this case, if the senior officer arriving takes the salute from the senior most officer hosting him, then he can simply not salute back or casually/verbally wish (Salam) or shake hands and move on without having to return a formal salute from every other junior officer. The way to do that is to not don on the head-cover to avoid saluting back in a polite way.
Those saluting know (they are told in advanced usually when a foreign military dignitary is visiting) that they will not get a salute in return, only a hand-shake or a verbal greeting from the senior officer.
You may have noticed that this happens quite a bit in large darbars, Eid, visits to formations etc. where the senior officer is meeting many personnel and they may not have their head-cover on to avoid having to salute potentially tens and hundreds gathered there.
Sometimes things turn comical and as such some leeway (as per the customs) is allowed. Although I admit, this "dheela" salute is neither here or there. Either you don't salute at all or do it properly with head-cover.