When a foreign dignitary was on a State visit the host was responsible for the security of the visitor. This was guaranteed by providing a military formation to do so and this was usually really inspected by the visitor.
Today Americans – for example – do not trust this old tradition and provide their own security (largely). But it is still a part of the traditions of diplomatic protocol and seen as a big insult if such a defilee is not offered. Each country is allowed to have its own tradition for that, but you have to offer something along those lines.
Then there is some additional symbolism meant to be conveyed:
The symbolic intentions of a reception with military honors are above all:
Representation of state sovereignty to the guest (demonstrating state freedom and ability to act),
Presentation of the weapons during the front line walk as a mixture of demonstration (I am armed) and presentation of the weapon for checking for ammunition (I have not loaded).
Achieving a good impression with the guest of the discipline and the level of training of the own armed forces (protocol units are therefore usually subjected to special drill and hard drill training).
Honour guards are older than dirt, but this kind of ritual originated from the honores regii and emerged as we feel to know it in early modern Europe, mainly during the 30 years war at Münster and Osnabrück and pretty much solidified after the congress of Vienna.
It would be false, however, to give the impression that it was monarchs alone who wished their honor and glory to be upheld in ceremonial matters. Early modern republics had the same goal. A Venetian ambassador prefaced his relation to the Venetian Senate about his embassy to Rome with several pages reminding the senators how he had previously been successful in getting the Spanish government of Philip IV to give Venetian ambassadors the same honors as those given to the ambassadors of "other crowns." Half a century later, Dutch ambassadors in Paris claimed they should have the same honor guard and drummers as the ambassadors of crowned heads. If there were reason to fear a representative might not be accorded proper honors, the Dutch even went so far as to appoint a minister without rank in order to avoid the problem. All early modern rulers, from Holy Roman Emperors and popes to princelings and the leaders of unimportant city-states, exhibited the same concern for their own honor.
Early modern Europeans and later historians have traditionally viewed the significance of diplomatic ceremonial in terms of princely glory and honor. This is appropriate but not sufficient. The study of diplomatic ceremonial can clarify the relative positions of states in the international hierarchy by showing changes in the patterns of diplomatic ceremonial. Used with care, diplomatic ceremonial can serve as a barometer for relationships between states and rulers in the short run, especially if we are aware of the possible meanings of nonverbal forms of communication. It can also aid our understanding of the role of ceremonial in defining and maintaining the positions of rulers within early modern states. But the study of ceremonial has wider implications. It helps us to understand early modern civilization better because of the widespread importance of ceremonial and ritual in that society. In any case, it should be obvious that ceremony was not just the empty gestures of men who had nothing better to do with their time. Ceremonial was an essential and significant part of early modern diplomacy.
William Roosen: "Early Modern Diplomatic Ceremonial: A Systems Approach", The Journal of Modern History, Vol. 52, No. 3 (Sep., 1980), pp. 452-476.
The honoris regii – and here especially the honour guard – should have been given to any representative of a sovereign visiting on official business after the peace of Westphalia, but while the Swiss were undoubtably sovereign afterwards, their emissaries were frequently denied the ceremonial honours, especially by the French. It was for a time unthinkable to make a king pay that much respect to a peasant from a 'democratic' community, like the Swiss, then the Dutch or even the suspect Venetians.
("the honour of a king", cf Barbara Stollberg-Rilinger: "Die Königswürde im zeremoniellen Zeichensystem der Frühen Neuzeit", 2002: PDF, German.)