The heroes of Water Margin come from lower-class or marginalized backgrounds and act according to strict moral codes whose allegiance transcends everything from class origin to family ties to gender identity—and the law itself. And in a society as strictly Confucian as dynastic China, where historically strict adherence to the letter of ritual was valued above actual belief, this last element is crucial to what has made this such a radical and enduring tale in the history of Chinese culture.
Both the Song dynasty (which forms the setting of this story) and the Ming dynasty (when this most famous iteration was first published) saw a rise in interest in Neo-Confucianism, which, in short, distinguished itself philosophically from other schools of Chinese thought by emphasizing the role of individual reason in forging a harmonious relation to the world, as opposed to both the lofty metaphysics of Buddhism or Daoism and the slavish adherence to ritual promoted by classical Confucianism. This context informs the subversive application of the term "hao han" to a group of social misfits who have elevated themselves above traditional centers of authority by dint of their rationally derived morals and fierce loyalty to one another.
Finally, while hao han (好漢) translates literally to "good guy," the second character, han (漢) has specific linguistic origins in distinguishing ethnic Chinese people from "barbarians" or outsiders—it's the same word used today to denote people of specifically mainland Chinese origin, or to specify the language spoken in Beijing as opposed to that spoken in Hong Kong, Shanghai, or Taipei. Thus the bandits' use of the term for one another implies a certain attitude toward their own identity with respect to the tension between moral action and official position in establishing one's right to membership in a "civilized" society. The use of the term in this Ming dynasty text will reflect all of the 500 years of historical change that separates it from the events it is based on, with all of the ideological shifts those centuries of upheaval entail.