General lack of house training can be a cause of your dog peeing indoors. This is obviously more common in puppies. With any training, follow the golden rule of ‘reward the behavior you want, ignore the behavior you don’t’. Punishing the behavior of peeing inside can confuse your puppy into thinking you don’t want it to urinate or defecate, and can increase the anxiety around the act making the problem worse.
If they do toilet inside, remove them and place them where you would like them to toilet, then give a gentle pat. In conjunction with this, take your puppy outside regularly, and especially after a meal. When they toilet outside, quietly reward them with a treat or pat. Try not to get too over-excited about it. Read more about how to toilet train your puppy here.
If your dog is easily excited/anxious (the two can go hand in hand) then this can cause temporary loss of bladder control. This is common in puppies who are learning how to control their bladder and they can sometimes pee without knowing when they are especially excited.