OP typically dogs go to the bathroom inside for a few reasons. First they have to go. Make sure they have access to the outdoors regularly. Small dogs have small bladders meaning more frequent potty breaks. Second reason is lack of exercise. When dogs are deprived of regular walks where they have the opportunity to do "dog" things like mark there territory, sniff, search for small animals, ect, they will have built up energy and this energy will show itself in the form of misbehavior. Third reason is it is instinctual to mark territory for males. So if there are other dogs who frequent, a female dog around, or they are not fixed you will have more issues than usual.
If you want to solve the problem scolding is almost never a good option. You rub their face in it bc u are mad or u think they will understand. That is not the case as they have no concept for why you are rubbing their face in their piss. If you dont catch them in the act you are not making the situation better by scolding. Catch them in the act, stop them calmly, take them outside, praise them for doing it outside. The older the dog the more engrained the habits. Getting mad wont help, it just creates distrust in your pet. If you are mad at your pets behavior, you have failed them, they have not failed you.
Communicating with pets is like a puzzle. You are the one who demands the rules to be followed and if your dad spoke chinese and then yelled at you when you didnt do the chores bc u couldnt understand him that would be frustrating and cause tension in your life. Your dog feels the same. Change your approach and your dog will change his actions.
Hope this helps