Question: I kissed my crying son in Shul to placate him, though was told that I shouldn't have. Yet, I’ve seen others kiss in Shul. What are the parameters?
Answer: The Rema (OC 98:1) writes that fathers should not kiss their children in Shul, as Shul is a place where one should demonstrate their love to Hashem (Sefer Chassidim 255).
R’ Avraham Yitzchak Kook (Orach Mishpat OC 22) writes that this prohibition applies to kissing other family members and friends, too.
The Ben Ish Chai (Vayikra 11) writes that while one shouldn’t kiss one’s young children in Shul, the sefardi minhag of kissing the hand of a Talmid Chacham is commendable because it is done out of respect rather than personal affection. Likewise, one may kiss one’s father or Rabbi after being called up for an aliyah where that is the accepted practice (See Kaf Hachaim OC 151:6). R’ Ovadia Yosef (Yechave Daas 4:12) explains that showing them kavod is a form of honouring Hashem, just as one must stand for them, even in Shul. One shouldn't kiss any other relatives who one isn't obligated to honour, however.
Others hold that as this Halacha is written in Hilchos Tefilla (as opposed to Hilchos Bais Hakenesses) this prohibition only applies during Davening (See Piskei Teshuvos 98:7).R’ Ephraim Greenblatt (Rivevos Ephraim 2:66) quotes R’ Ovadia Yosef who writes (Yabia Omer EH 3:10) that when making a chuppa in a Shul, one must be careful not to embrace one’s relatives. Thus, kissing is always forbidden in Shuls. One would be allowed to kiss one’s child if they are crying, however, as this serves to calm them, rather than show affection.