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, sallallaahu ‘alayhi wa sallam, is His Slave and Messenger.
Perhaps our dear questioner means by the first Hadeeth that Hadeeth which states: A man from the Ansaar came to the Messenger of Allaah, sallallaahu ‘alayhi wa sallam, and said, ‘If a man were to find with his wife a man and if he were to talk about it, you would lash him; and if he killed, you would kill him; and if he were to keep silent, he would consume anger.’ Whereupon the Prophet, sallallaahu ‘alayhi wa sallam, said: ‘Allaah, solve (this problem)’, and he began to supplicate (before Him), and then the verses pertaining to Li‘aan were revealed. [Muslim and other narrators] In another narration: “If he speaks about that, he would be lashed. If he kills, he would definitely be killed.” [Ahmad]
Al-Bukhari titled this Hadeeth under “Chapter on the person who sees a man with his wife and kills him”
Most scholars are of the opinion that whoever kills a man who is found with one’s wife should be killed in legal retribution though he would not be accountable before Allaah if that man was married and had sexual intercourse with the killer’s wife. Ibn Hajar said, “Majority of scholars said that this man should be subject to legal retribution.” Ahmad and Is-haaq said, “If the killer proves that the killed person was with his wife, the blood of the killed person will be valueless.” Ash-Shaafi‘i said, “If the killer knows that the killed person was previously married and had sexual intercourse with his wife, he will be forgiven before Allaah. However, the worldly ruling of legal retribution should not be waived.”
There is no contradiction between this ruling and the Hadeeth of Sa‘eed ibn Zayd that the Prophet, sallallaahu ‘alayhi wa sallam, said: “Whoever is killed defending his wealth is a martyr, whoever is killed defending his religion is a martyr, whoever is killed defending his life is a martyr and whoever is killed defending his family is a martyr.” [Abu Daawood, At-Tirmithi, An-Nasaa’i and Ahmad] This Hadeeth indicates that whoever is killed in one of these cases is a martyr; however, this ruling does not negate legal retribution in case of failing to prove the aggression. The issue of martyrdom is relevant to the Hereafter whereas the issue of legal retribution is relevant to the rulings of worldly life. Hence, there is no contradiction between these rulings.
Allaah Knows best.