It could be anxiety that is causing him to pee. Since you are in an apartment it could be a particular sound that is causing it, since it's not all the time. I know my boy Vegas has anxiety and will sometimes poop in the house when I leave, but it's not all the time. I just clean it up and am thankful I raw feed because the poop is hard and easy to pick up. But your dog, I'm not sure how to break it. Maybe set up a video so you can watch it if he does go and see if there is any triggers.