How might changing topic affect a career in academia?
If you do a masters thesis on topic X and topic X is not too far from topic Y, for example, if they are both computer science topics, and your academic record is good and your background is sufficient to make the transition, then I don't see any problem making the change at this level. You can catch up on whatever knowledge you need while learning about and researching topic Y. This will not look bad. After you obtain your PhD, people will be less interested in your masters.

Changing later in your career is also possible, though a little more difficult.

One positive point about being able to demonstrate that you can change topic is to show that you are not a one trick pony, meaning that you are able to apply yourself at the highest level to different areas.

Indeed, as interests in the field shifts and technology changes and new topics open up, it will often actually be necessary to change topics in order to survive in the field. If people (or just you) lose interest in a topic, then you need to be able to change.

But it is also good to demonstrate that you can commit to one line of research. Apart from the advantages this gives you, such as having a deep knowledge of a specialised topic, it demonstrates your commitment and can be used to show that you have and follow a research strategy.