Your Kamailio is using the RURI for routing the BYE and not RR header.
My tip is to xlog your Kamailio config in order to see if the subsequent BYE request will
run the loose_route function inside your route[WITHINDLG].
if (loose_route()) {
if (is_method("BYE")) {
xlog("L_INFO","Running loose route for subsequent BYE request from $si :
$sp \n");
}
I also recommend not to remove any record route headers when engaging with MS Teams - so
do not remove any RR header and make sure your FreePBX include record route header
originally received from Teams.
Regarding the call disconnect: Might be that the corresponding ACK or the 200 OK
(depending on Teams being UAC/UAS`) is not handled from MS Teams side. Again, make sure
not to replace to much of the headers received from Teams apart from what is mentioned in
the MS Teams Kamailio guide.