I have a cat of 11 years, who did exactly the same thing when he was a kitten of about 10 months.
I think it's a kind of hormone related growing up thing. I didn't let mine into the bedroom when I couldn't watch him all the time & when he sneaked in to wee on my bed, I scared the living daylights out of him & quickly that did the trick. Obviously I only mean scare him with noise, never smack a cat or rub it's nose in its mess.
He has never done anything like this since , so hopefully yours will also grow out of it if you let him know loud and clear that you are not happy...while giving him lots of positive attention when he is behaving himself.
That's only my opinion...I'm not saying it'd work for every cat. Good luck.