Chastity as such was relatively little discussed in the ancient and medieval periods; it gets mentioned, but most discussion that can be recognized as being in some way about chastity is focused on particular practical issues in specific social contexts -- consecrated virginity and marriage being the most common contexts. To find any extended discussion of chastity as such, rather than chaste actions, one must look at those who were deliberately trying to be very thorough.
Aquinas, of course, takes chastity to be a subjective part of temperance (2-2.143.1). Temperance is often the most difficult of the cardinal virtues to pin down because it only draws hard and fast lines at the extremes; this is because it is concerned primarily with restraint in matters of pleasure in order to promote beauty and avoid shamefulness in action. Like all cardinal virtues, Aquinas assigns it 'parts'. Subjective parts are just versions of the same virtue with a specific matter -- in this case, quite obviously, the matter is sexual pleasure. Everybody recognizes that the pursuit of sexual pleasure must be moderated in light of what is reasonable; thus it is clear that there would have to be some virtue of moderation with respect it (2-2.151.1). It's important to grasp that chastity understood in this sense does not concern sex alone; it concerns all things relevant to the pursuit of sexual pleasure, because moderation in that pursuit requires attention to all the major circumstances of the pursuit. So it also pertains to kissing, hugging, and the like, which can function as signs and circumstances of the pursuit of sexual pleasure.
The question arises, of course, of how chastity relates to virginity, which involves abstention from sexual pleasure (2-2.152). Virginity in the proper sense is a virtue, because it is not mere abstention from sexual pleasure but abstention in order more perfectly to fulfill a higher purpose, namely, in order to contemplate truth. (Aquinas says quite explicitly that abstention from sex solely out of aversion to sex is the action of a vice, namely, the vice of insensibility.) So how is virginity related to chastity? Aquinas says that virginity is to chastity as magnificence is to liberality, so his answer requires a brief detour through those virtues.
Liberality (2-2.117), a potential part of justice, is the virtue concerned with making good use of one's wealth; there are two ways one may do this, namely, by spending it an appropriate way or by giving it for the good of others, but the latter is the more perfect expression of the virtue. Magnificence (2-2.134), a potential part of fortitude, is the virtue concerned with accomplishing great works with one's wealth. One cannot have the virtue as such without the money it would take actually to accomplish a virtue; but it is inseparably linked to liberality in that the truly liberal person will either be actually magnificent (if the money is at hand) or have a proximate disposition to being so (if it is not). Note, incidentally, that the line is merely the material resources required to do great things, which one then does, not how much money one has. What distinguishes the two is that magnificence adds a special excellence to that of liberality, namely the notion of something difficult to achieve (which is why it ends up as a potential part of fortitude despite being so closely linked with a potential part of justice). Liberality provides the formal part of magnificence; but magnificence as such requires a material element that liberality does not automatically provide. Because of this, magnificence has the quirk that if you lose it, repentance can restore the 'formal part', i.e., liberality, but it cannot guarantee that you will get the 'material part' back -- merely repenting will not increase your bank account, or, one supposes, repenting would be much more popular than it is. However there is a further quirk in that virtues are only lost by actions pertaining to vices; if you have lost your money through no fault of your own, you have not lost the disposition to use your wealth in a magnificent way, but simply lost the opportunity to do so, like someone cut off from his funds; to lose magnificence requires acting miserly.
Likewise, virginity, taken as a virtue, adds to chastity a special excellence, the integrity of the flesh for a higher purpose, which can be considered a sort of 'great work' of temperance. Thus virginity requires more than being chaste, but one who is genuinely chaste, whether as married or as widow, has a character such that it would be disposed to the virtue were that appropriate. Just like magnificence, virginity gets its formal part from chastity but adds to it an additional material excellence; thus if one loses it (the virtue, not physical virginity) one cannot be guaranteed to get the virtue back. However, if one loses one's physical virginity through no fault of one's own, as has happened all too often in history through rape, one still has the virginal disposition, and thus the virtue of virginity; that can only be lost by unchaste acts.