They may be deterred by possible consequences, see the law as a legitimate authority, obey the law so as to better coordinate with others around them and society at large, or they may do it to signal their beliefs or morality. For most law-abiding people, their reasoning is likely a combination of the above factors.