Will an off-topic Masters hurt my chances of a PhD place?
Don't ask us.
Contact your favourite three prospective universities for your cosmology PhD. Better still, contact your favourite three supervisors for your cosmology PhD. Ask them:
What Master's dissertation topic will prepare me best for my intended cosmology studies?
What Master's dissertation topic will make me most likely to be successful when applying to study a cosmology PhD?
(The first question is much more interesting than the second).
You will find enthusiasm for engaging with your question and your situation, because you are expressing specific interest in their field and because you are not asking them to decide anything about your application – since you have not applied. Quite a lot of people in senior levels in cosmology are interested in cosmology and are glad to find interest in cosmology in other people.
Martin's answer is good, but I'd like to share my experience anyway, which is that the topic of your thesis is less important than the quality of your work.
That is to say, publications, good recommendations, good marks, and awards/accolades are much more valued than the specific topic that you worked on. People don't expect miracles from your master's thesis, rather they want to know whether you have the necessary knowledge/skills to embark on a PhD.
Yes, a thesis topic which aligns perfectly with your interests is ideal, and it may be a minor disadvantage if you can't work on such a topic, but ultimately it's not up to you what topics are available to you, and people in academia recognise this.
In addition to the above, it depends very much on your funding (we are discussing the UK system here). If you will be self-funded, the supervisor will primarily look at your ability to finish (complete), and second to how open you are to work in an area the supervisor(s) is/are comfortable with. The limit here is how many students the supervisor can practically supervise with sufficient attention to each student.
If however you seek to have some scholarship you will likely be working on a previously specified project with certain targets in mind. You will be competing against more students (it's paid, there is more interest; direction can be helpful; there are less places available). In these cases it depends on the project and supervisor. Sometimes there just is a certain piece of work that must be completed. In other cases, some serendipity is possible and may lead to great research outcomes.
Even in the funded case the quality of your work, and especially thinking is the most important. Where a masters requires some independent, reflective, insightful thought, a PhD requires it absolutely. Working from that perspective, as a supervisor (not in physics though) I would expect you to have considered what would/could be the best solution. That you would not be able to do the project of your first choice would not really be held against you (unless it was for lack of exploring ways to do so anyway), but you should have good reasons for the second choice. Those reasons could be that you want to be broad and love that topic as well, or because it is closely aligned.