Scratching, yawning, sniffing, etc. are actually calming signals. Dogs use these signals all the time when trying to calm down other dogs. They also use them to calm down people! When they sense you are upset (they're not obeying your command!) they try to calm you down by doing these behaviors. I would work on your response. Try to switch to positive training and I bet he'll stop scratching!