The issue is moisture.
I had the same problem, the pen got wet while I was taking a photo in a pool.
The phone was fine the pen though got some moisture in it and started doing exactly as you describe.
I took the pen tip out and left the pen in a hot area (110f) for about 3 hours so the moisture evaporated, put the tip back in and problem solved.
Unfortunately Samsung sell waterproof phones with non.waterproof accessories!
Thankfully it's a quick and easy fix!