1650s, "having a characteristic agreeable taste; having a flavor supposed to be imparted by the soil" (of wines, fruits, etc.), from race (n.2) in its older meaning "flavor" or in the sense "class of wines" + -y (2).
The extended meaning "having a quality of vigor" (1660s) led to that of "improper, risqué," attested by 1901, which probably was reinforced by the phrase racy of the soil "earthy" (1870). Related: Racily; raciness.
Figuratively, that is
racy which is agreeably fresh and distinctive in thought and expression ; that is
spicy which is agreeably pungent to the mind, producing a sensation comparable to that which spice produces in taste. [Century Dictionary]