I found this bug a while back. What happens is that the server does not recheck movement orders for an army unless that army is attacked. Therefore, if you teleport in forces that would disrupt movement without actually attacking the force in question, it will have no effect.
In the case I tested there was only one province that an army could move through in order to get to a second prov. But I teleported an SC in to cap the middle prov. The army moved "through" that province regardless of the fact that I held it. It is the same scenario for you except that the province in question just happened to be containing a castle (which is what prevented combat with the main force from taking place).
It's definitely a bug. Whether anything will be done about it is anyone's guess. I brought it up... I dont even recall how long ago.
Oh, and as for the armies "switching places" thats not technically what happened. The order of events would have been as follows:
*Magic Phase: Teleporters gain control of castle prov
...
*Friendly Move Phase: Your army moves to the (now friendly) castle prov
*Attacking Move Phase: Enemy army moves into your (now vacant) prov