Based on rom hack editing, you can adjust how optimally the AI plays against the player, so the game makes decisions based mostly on type advantage, remaining HP, the moves it has listed, etc.
It's not necessarily that it recognizes what can and can't hit shedinja, but how wisely the opponent thinks based on difficulty. A youngster or generic trainer like that might have a lower setting, so that's why they use tail whip or something on you when you're low HP and could just win but don't. A gym leader, elite 4 member, maybe an ace trainer, etc would have a higher level. It's basically a general way of attacking that works well, but can have varied results when you have more complex Pokemon abilities or situations like Shedinja, Zoroark, etc.