I am not quite sure what exactly your question is (might be worth editing your current question). But, the Lechem Mishneh, in the commentary on this halacha writes:
"What is full teshuvah ('repentance')?... This is full teshuvah..." In Tractate Yoma 86b, they said: What is a ba'al teshuvah ("one who has repented") like? Rav Yehudah said: It is like one into whose hands some transgressive matter came one time, but, in the second time, that person was 'saved from it.' Rav Yehudah showed [further what he meant by stating]: With the same woman, at the same time, at the same place. And the reason for this, according to Rashi, in his words: So long as it is all and all similar to the time when the person would have failed and had their [evil] inclination conquer them and say to them, "Look, it is the same What's-Her-Name and the same place, and it's the same time; get up, and do what you've done before." (That's the end of Rashi's comment." And our teacher [Maimonides] did not write [specifically] "one time" and "second [time]", for it was not in his version [of the Babylonian Talmud]; rather: It is like one into whose hands some transgressive matter came, and Rav Yehudah showed an explanation: With the same woman, at the same time, at the same place, etc.. And such is the language of RYF (i.e., Rav Yitzhak Alfasi) in Hilkhot Makkot ("The Laws of Striking"). "And in that time" means "with the strength of one's body," which is to say, "in the time of one's youth."
You ask why the Rambam uses illicit sexual relations as a example in this halacha. It might have something to do with the fact that illicit sexual relationsare one of the three cardinal sins, see here which the Torah describes as "a great sin".
Furthermore, you state: "surely he is transgressing hilchos yichud?"
I do not think this is the primary focus in this halacha. The focus of this halacha is that Rambam explains what complete teshuva is, what is a baal-teshuva? How does a baal-teshuva acts when confronted with the same challenges as before, the challenges that made him do a certain sin. Rambam then goes on to say that a person is a baal-teshuva, aka someone who has done a full teshuva, when:
the same context in which the sin was done, so "same place, same "woman", same time etc..." is applicable at another time, but, despite of his urges, the person choses not to "follow his heart", and instead, choses the right path to follow. See also the commentary of the Maaseh Rokeach.
When doing teshuva, G-d often places a person in exactly the same situation in which he sinned. This is done by G-d in order to help the person repent, and make sure that the same error is not done again. See: Mesilas Yesharim, chapter 1, by R'Chaim Luzatto:
The Holy One, blessed be He, has put man in a place where the factors which distance him from the blessed G-d are numerous. These are the physical lusts which if he is drawn after them, behold, he draws away and goes ever further from the true good.
Thus, we see that man is truly placed in the midst of a raging
battlefield. For all matters of this world, whether for the good or
for the bad, are trials for a man. Poverty from one side versus wealth
from the other. This is as Shlomo said: "Lest I be satiated, and deny
You, and say, Who is G-d? or lest I be poor, and steal..."
(Prov.30:9). Tranquility on one hand versus suffering on the other,
until the battle is waged against him from the front and from the
When G-d places a person in exactly the same situation, in a situation in which the person used to stumble and sin, but this times is strong enough to keep following the right path. Then his teshuva is complete. That is what the Rambam is talking about.