I think you're posting this because your SPen is secured in its place, right? I know there's a setting to automatically switch to Handwriting Mode when pulling out the S-Pen, but it SHOULDN'T happen if the S-Pen is in it's place. Try disabling that option and see if it happens again (both when pulling out the S-Pen and while keeping it in). If it DOES happen again, then it's a software issue and you should have your phone checked (or maybe do a factory reset?... have you updated OS lately? Might have to do that, too). If by disabling the option the behaviour stops, then probably you have a problem with the S-Pen detection and, I'm afraid, this could be a hardware failure either in the sensor inside the phone or in the passive circuitry inside the S-Pen.