This is possible both ways that you have outlined but if you want it to be processed by an inbound route on FreePBX B the context of the IAX trunk needs to be from-external rather than from-internal. If you change it to from-external it will break the ability to dial extensions from one site to the other.
If this were my site I would set up a second IAX trunk set to from-external then send calls from the outside over that trunk.
Others will probably jump in and say there is a better way to do it.
This also works perfectly for me. All phones of all branches are registered at side B in this example via VPN. But is there a solution in case side B is down? Therefore the IAX runs to nowhere in this case.
However, side A yealinks can register at the same time at side A (locally, fallback). But there is no possibility to get an incoming call for B offline situation, since I didn’t found a solution to route calls by the inbound route to a local extension when the remote extension is down. Any idea? For inbound routes there seems to be not a similar logic as it is for outbound routes. What’s my goal: Let side A phones work even if side B is down. Otherwise when B is the head-office which is down, all branches are not reachable in the same moment. Any solutions I found, maybe ringgroups, other kind of extensions do not offer a choice for the online situation (B is available, use IAX first), and use local extension if IAX is down.