2 Answers
2

The remark of the Shulchan Aruch in Even HaEzer (21:2) is based on the Rambam (Hil. Issurei Bi'ah 21:17) and seems to be ultimately derived from the gemara in K'suvos (bottom of 72a). However, in light of the statement of the Shulchan Aruch elsewhere (OC 75:2, based on the mishna in K'suvos, 2:1) that it is customary for maidens to appear in public with uncovered hair, the Beis Sh'mu'el (EH 21:5) interprets the Shulchan Aruch's reference to unmarried women as meaning widows and divorcees, and the Chelkas M'chokeik (EH 21:2) interprets it as a reference to non-virgins.

The Magein Avraham (OC 75:3) reconciles the two statements of the Shulchan Aruch in a different way. He interprets the use of the expression "פרועות ראש" in Even HaEzer (21) as prohibiting unmarried women from appearing in public with loose or disheveled hair as opposed to uncovered hair. (Incidentally, see this question and associated comments). Using similar reasoning, R' Ya'akov Emden seems to require braiding and/or some degree of covering (from a kerchief or the like) for an unmarried woman (Mor U'k'tzi'a' OC 75).

In any case, common custom follows those opinions that permit women who were never married to leave their hair uncovered.

Just a broader overview on Fred's answer: many, many poskim would say that erva can be subjective and depends on society; in a society where the modest non-Jewish single women don't cover their hair, the Jewish women don't have to either. (Though Rabbi Willig's opinion is that covering the torso is required, regardless of cultural norms.) Hair covering for married women, however, appears on the books to be an objective requirement.