Are you asking this question because you actually witnessed a Shedinja use Substitute successfully? I have never seen it myself but I did find someone talking about it, not sure if it's from Gen 4 onwards though...well, the post is 8 years ago.
I quote:
So, I just got myself a Shedinja. For some stupid reason, it can
learn substitute. I decided to try teaching it. Last Gen, I'm pretty
sure Sub always failed with Sheddy. This gen, it succeeds, and Sheddy
does not lose any life points. Any attack then destroys the sub
(damaging or no) since it has 0 HP.
Link: https://gamefaqs.gamespot.com/boards/696959-pokemon-x/67548417
If you are asking how is Shedinja able to use Substitue successfully based on actual experience, then I suppose this is indeed possible. However, no one probably knows why the change in this mechanism, if it works as described there in the quote, it seems fun but rather useless.
If the above anecdote is just a troll or fake story, then I agree with Cicada as well as my personal experience, Shedinjas shouldn't be able to successfully use subtitute at all. If it is indeed illegitimate, please feel free to tell me to just delete this.