The fly is always attracted by bad odors, such as bodies in a state of putrefaction. The fly repellent therefore recalls the idea of death.
This is to remind the king that he is mortal and to bring him more humility in his governance. In addition, the king is attacked from all sides by evil spirits during his exits. Thus, the fly swatter keeps evil spirits away from the king.