It is not a coincidence, but it is not trivial. In this case, the exchange of shares has NPV=0 for both. Neither A nor B earns anything in the transaction because the price of B is exactly half of the price of A. If this is not the case, the result will not hold, and the price will change.
In reality, if this is not the case, either B does not sell or A does not buy. Hence, it must be the case (in equilibrium). Nonetheless, in an exercise, it might not.