All perfect praise be to Allah the Lord of the Worlds. May His peace and blessings be upon our Prophet Mohammad and upon all his family and companions.
The Illah (Legal cause) for differentiating between lashing and stoning to death as regards the penalty of adultery/fornication is Ihsan (Married or used to be married and had sexual intercourse). The penalty for the married man or woman who commit adultery or fornication is stoning to death (Rajm) while the unmarried is lashed a hundred times.
Ihsan is a set of conditions, which once met by the man or woman committing adultery or fornication, their penalty is stoning to death. They are: Having reached the age of puberty, being rational, being free, having had sexual intercourse during a valid marriage. However, if the marriage is concluded but not consummated, then the concept of Ihsan doesn`t apply to both parties. Also, if sexual intercourse did take place but the marriage was invalid, then the concept of Ihsan doesn`t apply to both parties as well.
An-Nawawi {May Allah have mercy on him} said: "Al-Muhsan is the responsible, free-even a Dhimmi (Non-Muslim living in Islamic state with legal protection)-man who has inserted the head of his penis into a woman`s vagina during a valid marriage, and this is according to the stronger opinion of the Shafi scholars." {Menhaj At-Talibeen,pp.132}.
Therefore, whoever meets these condition once in his life is considered a Muhsan and it isn`t conditioned that all of them must be present while committing the act of adultery/fornication to execute the penalty of Rajm. Rather, it suffices that he has had intercourse with wife once during a valid marriage, even if he divorced her afterwards or she died, so the concept of Ihsan applies to this adulterer/fornicator. The evidence on this is that 'Ubadah bin As-Samit (RAA) narrated that the Messenger of Allah (Peace and blessings be upon him) said: "Receive from me (this revelation), receive from me (this revelation). Allah has ordained a way for those women (unmarried females who committed adultery). When an unmarried man, commits adultery with an unmarried woman, they should receive one hundred lashes and be exiled for a year. If they (fornicate while they) were married, they shall receive hundred lashes and be stoned to death." {Reported by Muslim}. Here, the stoning to death is conditioned upon being married and this applies to whoever had sexual intercourse during a valid marriage, even if he divorced his wife later or she died, and this is according to scholarly consensus. And Allah The Almight Knows Best.