Is it normal for my masters advisor to ask me not to share code from my masters work with my PhD advisor, and not to continue with the same topic?
II don't know anything about the law in your country, but I think that the request of Professor A has a weak justification:


As lang as you wrote the code in the course of your master
program, your advisor has no right. The algorithms should be considered as public domain (unless you've
signed an NDA). It is different, if (parts of) the code are done by
others.
Being a master student does not constitue an employment relation. There is simply no base for any restriction to your further academic career. 


Beside of this, I consider the behaviour of Prof. A (given you've presented all facts) as a bad academic style. Knowledge exchange, a.o. by exchange of people is a well established academic method. To answer your direct questions:


While conflicting loyalty may be a typical problem, I've never heard that a colleague of mine issued such request. Your course of actions depends (of course) on practical issues, too: Is there any danger that Prof. A prevent you from getting the master degree? If so, explain the situation to Prof. B and try to reach an agreement that you "officially" apply after you get your degree.
As I explain above: IMHO no. I would be a waste academic
resources, i.e. your knowledge and abilities. (Beside of this, it is
always a good advice to at least widen your area of expertise as
well as include at least few topics that are totally new for you: It
make you a better researcher)