All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger. We ask Allaah to exalt his mention as well as that of his family and all his companions.
There is no contradiction about the stoning and the flogging for fornication and adultery. The first punishment for female fornicators and adulteresses in Islam was to keep them inside the house and for the males by harming them (by cursing and beating them), however, the scholars differed in opinion which ruling was first. Allaah has set a time for this punishment as He says (which means): {…confine them [i.e. the guilty women] to houses until death takes them or Allaah ordains for them [another] way.}[Qur'an 4:15].
Then the Sunnah came to clarify this method of punishment: which is stoning to death for an adulterer or adulteress and flogging the female or male fornicator, and putting him/her in exile for one year.
The Prophet said: "Take from me the religious ruling, take from me the religious ruling, Allaah has set a punishment for them, the virgin person is to be flogged one hundred times, and should be exiled for one year, and non-virgin person has to be stoned to death." [Muslim]
Allaah says (which means): {The fornicatress and the fornicator, flog each of them with a hundred stripes.}[Qur'an 24:2]. Though it sounds general, this verse applies to the virgin man or woman only, with the evidence of the Qur'an itself. As regards stoning, it is also confirmed by the Book of Allaah in an abrogated verse, but its ruling remained. 'Umar illustrated this in a narration reported by Al-Bukhari and this narration is mentioned in Fatwa: 85019. Stoning is also confirmed by the Sunnah as in the previous narration.
Allaah knows best.