The excerpt below is from Makkos 6b.
What good is a warning by a Shed, when we cant bring a shed to court to testify that he gave the warning?
Also what good is a warning by one's self, when there is a law that one can't indict himself by his own words???
[Halachah Outlines, Makos 6]
(i) (Rava): The warning can be even by himself (Rashi - the victim warned him; Kesef Mishnah - the transgressor said 'I know that Beis Din will kill me for this') or by a Shed.
harvey/mechael, lost angeles
The court does not have to see the one who gave the warning. It is enough if witnesses testify that a warning was given by an anonymous being (a "Shed") or that the sinner himself acknowledged that he was committing a sin.
This is not considered indicting himself. It is occurred as part of the crime, rather than as part of the testimony.
Mordecai Kornfeld
Kollel Iyun Hadaf