Dogs, like other animals, act out of instinct and learned behaviour, but they can't make moral decisions. They can't think beforehand about what they are going to do, nor think about whether it is right or wrong to carry out an action. They can only obey their hungers and thirsts and appetites and then afterwards maybe feel 'Oh sh*t, Master/Mistress has thumped me when I've done this before, I'd better show submissiveness until they give signs that it's all over.
Dogs' instinct is essentially the wolf pack instinct, and they will obey a leader for survival reasons.