To understand this, you need to know there is a different meaning of "shy"
"Shy" in this proverb is a verb meaning "to flinch" or "to react negatively to". We still use the word with horses (and sometimes other animals), to describe their response when they encounter scary situations and panic. It is not the adjective "shy" meaning "being cautious/fearful".
The meaning of the proverb is that if you are bitten once, you will naturally flinch away from the bite the first time - but the next time you're in a situation where you might be bitten, you'll flinch away before you're bitten. In other words, if you're in a situation where something bad happens to you, in future you'll react as if that bad thing was going to happen again.
In answer to your question about parts of grammar, both "once" and "twice" are adverbs counting a number of events, numeralwhich can be called numeral adverbs, iterative numerals, or multiplicative numerals, depending on your grammar reference. "Once" is the count of the number of bitestimes you are bitten, and "twice" is the count of the number of times you shy.
Note that this reaction may be a good thing (learning from experience to avoid common hazards) or it may be a negative thing (reacting negatively when there isn't a real need to). The proverb can actually be used for both these meanings, which is interesting. Most proverbs have a "moral" meaning of what's good and bad, but this is more describing a situation and not exactly saying that the outcome is good or bad, only that it is what it is.