I'm being asked (by my advisors) to include a person I don't even know as author of my new papers, in which they haven't done anything. The reason seems to be that my work is based on source code that was written by the three of them in the past. These people have already published several papers that rely on this implementation. I don't think that if I write a different version on top of their code I owe them authorship. I have done this before using libraries and other open source software. I have never included the authors of the code as co-authors of my papers, so I don't see how this situation is different. Still, I'm worried that they might not let me use the code to complete my implementation. Interestingly, I had already started an implementation with a different version they gave me from some other student, that was too different from what I had to do, which is why I asked for this other version, but they never asked me to include this other student as co-author and they're only doing it now with this other person. Is my reasoning correct? What can I do?
In theory, you would simply cite their previous work implementing the software in your paper rather than crediting them as authors, especially if that software is broadly available - this is what someone else from another research group would do.
In practice, if this is software developed within a research group (rather than software made broadly available and used by others), writing key software elements of a project can be considered a strong intellectual contribution to that piece of work, even if that contribution is spread across multiple papers, and therefore may be treated as worthy of authorship. From your perspective up until now, you're responsible for the whole of the paper, but from your advisors' perspective perhaps they see multiple people working on aspects of the research question: perhaps they as the advisor/PI are setting some overall research goals/direction, someone is writing software to implement a particular algorithm, someone else (you) is using that software to test a particular theory, etc. You may not have met them (yet), but your advisors have. I've certainly had coauthors whom I did not know personally, because we've worked on different aspects of a project under the direction of someone else.
I'd say that if they have done no additional work towards your project and everything you are using of theirs has already been published separately, that would be reason to put them into the "cite them" category. If they have done additional work towards your project that has not been published, though, then I would strongly consider offering them authorship, even if they have done this work before you interacted with them. However, that offer of authorship should come with other responsibilities of authorship, including assisting in drafting and reviewing the manuscript and approving its final form. That is, they should not simply be given authorship without you knowing them, but that you might owe them the opportunity to be more fully involved in the paper before you publish.
Your advisors should help guide you on which of these choices is more appropriate, so I think it's fine to raise your concerns but to also keep an open mind to their thoughts of what is appropriate.
I think many people who post here on Academia.SE believe too much that having other authors credited on their paper dilutes their own contribution to the paper in the eyes of others. While that may be true for some fields, in others it doesn't particularly matter if you add some 4th and 5th authors. I would avoid outright "gift authorship" where people are credited as authors for added prestige or to let some senior academic collect paper trophies, but I think it can be a fair reward for people who do the trench work of building tools useful for the research that others do.
Another perspective that could be worth considering is the contributions that these new authors may bring. You state that they have not done anything for your project, but if they agree to be co-authors they could contribute with critical reading and discussion on your manuscript before submission. Remember that the work is not finished before it is published.