The problem was in invalid nonce value as you can
see from the debug message
0(3411)
DEBUG: auth [api.c:136]: auth_check_hdr_md5():
auth:pre_auth: Invalid nonce value received (ret 2)
I was debugging for a while and I was also analyzing pcap dump
when I realized that kamailioB was forwarding and both replying
for the REGISTER message eg. UA answered first for 401
Unauthorized from kamailioB with it's nonce which was of course
on both kamailio's invalid (kamailioB does not have UA
registered and kamailioA was expecting different nonce). This
was happening over and over and it was unable to sync the
nonce's so I was getting 401 Unauthorized over and over.
After that i just simply add exit() after the forward(), kamailioB stopped responsing
for the REGISTER and everything started to work.
I hope that this response will help in the future someone
who forget to exit after forwarding the request :-)