The issue here is that results are not meeting expectations and the more he fails the more he stresses about each throw. My experience is that this is a mechanical issue that then turns itself into a mental one.
My advice depends on where the kid is in the cycle and that is only going to come from the kid being honest with you. If he doesn't know what's wrong but stays mentally positive look for mechanic signs of the balk being driven into the dirt. Short stride, late release. Etc.
That said it sounds to me like he is in the mental stage of this since it works when there is no batter and falls apart once the real thing starts. The key to curing this stage is to eliminate the expectations of results. He executes when nothing is on the line but once the expectation of results present themselves fear of failure steps in and prevents proper execution. You have to do something with him where he mentally says "well if this doesn't work who cares because it's not normal." To use a different sport analogy, i have a friend who had the putting yips when putting right handed. Turned him around and told him to put left handed and the yips disappeared. I've seen guys with chipping yips start chipping one handed. The limited expectations of doing something you haven't practiced frees u up from the mental expectations.
I would try something new with him. Teach him to throw a cutter, change his windup to include a hitch do something to make him uncomfortable with the process. If it feels weird and he's never done it before he won't have the expectation of perfection or the fear of dailure. You will have freed him up to be an athlete again.
Last point, The road out of the yips is a long process. If you find a solution that works stick with it longer than you would think to. He needs a sustained period of mental success before attempting to revert to normal.