The control of the Appetites by the Moral Sentiments is recommended to us under the form of the Virtues of Chastity and Temperance: but the Virtue which carries the control of the Higher over the Lower Parts of our Nature deeper into the heart and soul, is more properly termed Purity. And hence, we place Purity as one element of the complete Idea of Virtue or Goodness.
The principle expressing this Virtue is thus, "the Lower parts of our nature are to be governed by the Higher."
Obviously this notion of governance by reason cannot be simply inconsistent with the gratification of bodily desires, which are necessary for both individual survival and the continuation of the species. These desires are not, in themselves moral in character; they are, however, the material for Virtue, which arises when we put them under an appropriate moral rule. Doing this for sexual matters is what we call Chastity, and the attitude of mind following from it we call Modesty; doing it for food and drink is what we call Temperance. Our desire for these things should always strive to treat as higher what is higher. Thus we should not eat and drink (for instance) solely out of love of food and drink. The accoutrements of a decent table "are to be indulged as subservient to the support of life, strength, and cheerfulness, and the cultivation of social affections" (EM §222). All our duties of Purity arise out of this proper subordination to higher purposes. Our meals, for instance, should be "so conducted, that they may not only satisfy the bodily wants of nature, but also minister to the cheerful and social flow of spirits and thought, which is a condition favourable to moral action" (EM §224).
In sexual matters, Whewell of course takes mere sexual desire to be something that must be subordinated to the desire for a true conjugal union (Em §230):
The direction of the Affections and Desires, here referred to, towards their proper object, Marriage, is the best mode of avoiding the degradation of character which is produced by their improper operation. Virtuous love, as it has often been said, is the best pre-servative against impure acts and thoughts. The Love which looks forwards to the conjugal union, includes a reverence for the conjugal condition, and all its circumstances. Such a love produces in the mind a kind of moral illumination, which shows the lover how foul a thing mere lust is; and makes him see, as a self-evident truth, that affection is requisite to purify desire, and virtue necessary to purify affection.
This doesn't cover the whole of the moral character of marriage, which is structured not just by the Idea of Purity but also by the Idea of Order (and the others, too, although these two particularly), but it is part of the reason Whewell takes marriage to be higher and more morally important than a mere legal arrangement could be.
Just as with other Virtues, we have duties not only to particular kinds of action, but also to the appropriate disposition, the Spirit of Purity, so that Impurity becomes foreign to us, and to the relevant kind of moral cultivation, so that we conform ever more in thought and action to the Idea of Purity.
Whewell makes clear that he regards Jeremy Bentham as his primary opponent on this topic; Bentham, of course, rejected the very notion of a virtue of Temperance on utilitarian grounds. Whewell sees the defense of the Principle of Purity as placing himself, on the contrary, in the camp of Joseph Butler. In the Preface to the Second Edition of Elements of Morality, he uses it as an example of why his approach is kin to Butler's:
If it be asked, to which of our English Moralists the Scheme of Morality here presented most nearly approach es, I reply, that it follows Butler in his doctrine, that by the mere contemplation of our human faculties and springs of action, we can discern certain relations which must exist among them, by the necessity of man's moral being. He maintains that, by merely comparing appetite and reflection or conscience, as springs of action, we see that the latter is superior in its nature, and ought to rule. This truth, I, with him, conceive to he self-evident; and I endeavour to express it by stating, as a fundamental Moral Principle, that the Lower Parts of our Nature are to be governed by the Higher. And I conceive that there are several other Moral Principles which are, in like manner, self-evident.
Not accepting the Butlerian position obliterates the distinction between man and beast, Whewell thinks, and leads to treating all tendencies, including moral tendencies, on par with each other (EM §223).
Since Whewell takes States to be moral agents, States have duties related to Purity, although as far as I can tell this seems primarily to be educational. States, of course, have no bodily desires themselves, and when the State does have a particular duty with respect to something that falls under Purity (like marriage and the family), it is often more concerned with Order. The Christian faith, as usual, incentivizes and intensifies the ordinary duties of Purity, insisting on the importance of inner control of bodily desires and giving a religious value to marriage itself. (As an Anglican, Whewell wants to play down a bit St. Paul's suggestion that virginity is better than marriage, which he represents as Paul's own opinion rather than a divine principle.) But, of course, aside from the religious significance of marriage, much of Christian exhortation on Purity has very little to do with sexual matters -- we are encouraged to be sober, not ruled by our bellies, not greedy, grave rather than frivolous, modest in dress, and the Christian faith gives a special reason to do these things, namely, that we should act in a way appropriate to children of God.