@Metaphor : do you believe that, if the state learns that the man who accepted fatherhood is not the biological father (which they assume he didn't know either), it should should automatically transfer legal fatherhood to the biological father?
No. What would make you think I support any kind of 'automatic' transfer of legal fatherhood?
What if he actually does know he's not the biological father (because they informally but consensually used an acquaintance as sperm donor and never thought it relevant to tell the authorities? Should he have to fight to remain a father if the sperm donor doesn't honor his part of the deal and demands to take over?
No. A sperm donor is, in fact, the textbook case for being a bio father but having no rights and no responsibilities towards the produced offspring. I should say, they ought be the textbook case, as some jurisdictions pursue sperm donors as if they had consented to being a social parent. I deeply opposed the rules in a case a few years ago when a man, out of altruism, donated his sperm to a lesbian couple. The lesbian couple produced a child, then split up, and the birth mother went on welfare. The State went after the bio father (the sperm donor) for money. That was wrong. Similarly, a friend of mine donated eggs a few years ago out of altruism to strangers (and donating eggs is a way, way bigger act of altruism than jizzing into a cup). If down the road, she demanded legal status as the mother, it would be wrong to grant it to her.
In short: no. A sperm donor knows and agrees he is giving up parental rights and obligations at the time of donation.
In most cases, I think parental rights (the right to have access or custody) go along with parental responsibilities (the obligation to provide material resources), but in some particular cases, bio fathers ought have the rights without legally-coerced responsibilities--the cases where adult women have raped boys and become pregnant.