No, you are not giving away anybody else's DNA.
In the case I mentioned, it was only after a court order from the High Court that a DNA sample of this man was provided.
As I understand it, they uploaded the child's DNA to Ancestry and found some distant relations who were not related to the mother.
That means that these people must be related to the father.
They would then have built a family tree (using purely records that are publicly available) for these DNA matches so that they could find all the cousins, aunts and uncles, second cousins etc of the DNA matches.
Somewhere within that family tree would be the father of the child. It would then be a case of finding a man of the correct sort of age who may have been in the right place at the right time.
They found a man in that family tree whose name the mother recognised.
Following that, they made an application to the court and the court ordered that a DNA test be done to determine paternity.
So, no, you are not giving away anybody else's DNA.
If you put your DNA on Ancestry and find a DNA match then that means that the two of you are related.
Knowing that, you can then look at other publicly available records, such as birth certificates and marriage certificates etc to find other people that you are both related to.