الْوَلَدُ لِلْفِرَاشِ، وَلِلْعَاهِرِ الْحَجَرُ
The above hadith is often found translated as
Narrated Abu Huraira:
The Prophet (sallallaahu alayhi wa sallam) said, "The boy is for (the owner of) the bed (al-waladu li al-firaash) and the stone is for the person who commits illegal sexual intercourse. (wa li al-'aahir al-hajar)'
This is an authentic hadith. It is reported by both Imaam al-Bukhaari and Imaam Muslim.
There are two opinions regarding the following phrase
li al-'aahir al-hajar
One view is that it means the Zaani is to be stoned.
The second view is that it means the Zaani has no right to the child.
al-Nawawi believes the second opinion is stronger
It has been said that the meaning is that the Zaani is to be stoned with rocks. This is weak. The reason being that not every Zaani is stoned. It is only the muhsan specifically who is stoned.
The child belongs to the firaash
This is the 'asl. The boy belongs to the husband of the wife who did Zinaa. The child does not belong to the man who did Zinaa with the others wife.
The only way the husband can deny paternity is by indulging in li'aan.
A husband leaves for a business trip.
He comes back after two years
His wife bears a child
The child will be attributed to him.
Ibn Qudaamah said:
Even if a woman gives birth to a child while the husband has been absent from her for 20 years, the child will be attributed to him.
DNA testing has no value.
The only way a husband can deny that the child is his is by indulging in li'aan.