Topological phase transition in a magnetic Weyl semimetal