As Edwin Ashworth notes in the comments, this is an instance of the subjunctive mood. From Wikipedia:
The English subjunctive is an irrealis mood used to form verbs in statements that do not describe known, objective facts. These include statements about one's state of mind, such as opinion, belief, purpose, intention, or desire. The subjunctive mood is also used statements that are contrary to fact, such as, If I were a giraffe, ... (subjunctive), as distinguished from, I am a human being. Subjunctive statements often occur in dependent clauses, such as the subjunctive example in the preceding sentence.
There are plenty of examples in the article that highlight the various uses of the subjunctive but in this case its use is that of a hypothetical situation:
It follows that any being, if it vary however slightly in any manner profitable to itself, ...
You could also write something similar to the following:
It follows that any being, if it were however slightly in any manner profitable to itself, ...
This form is not a necessary form and you could use "varies" if you felt like it. But this usage is completely grammatical (although it does sound a bit dated.)