Q. Since it is prohibited to kiss children in shul, since we should only show in Hashem’s house love to Him, why do chasidim kiss the hand of their rebbes when in shul?
A. Remo (O.H. 98: 1) indeed rules that one should not kiss his young children when in shul. in order to establish and promote in his heart that there is no loves as great as the one we must have for Hashem.
Poskim mention that this rule applies not only to small children, but even to grownups. (Sefer Chasidim 255, Binyomin Zeev 163, and others).
However, Poskim permit kissing as a demonstration of honor and kavod to a Rov or a Torah teacher or a Talmid Chacham. (Avos Derav Nosson 6, Maseches Kallah 1: 21, Orach Mishpot 22). Ben Ish Chai (Vayikra 11.), Yechave Daas (4: 12) and other permit kissing their hands.
See also Talmud Nedarim (9b) regarding Shimon Hatzadik kissing a nazir at the Beis Hamikdash and Moshe kissing his brother Aharon when meeting him on Har Hoelokim (Shemos ).
Horav Shlomo Miller’s opinion is that it is permitted
Rabbi A. Bartfeld as revised by Horav Shlomo Miller Shlit’a