Because good writers take great pains to establish the cognitive architecture of a character. That's how you know if a fictional person is acting "out of character". You may not KNOW what a fictional character is thinking (if they are even capable of it... DeCarte might argue that a fictional character does not ever truly "think" anything), but you can make a fairly good guess based on the established character.
no subject