Knowledge can be useful even when not publicly taught. Quietly acting on a rule may be a major benefit: returning entrusted goods after learning the duty of trust, or improving one's ablution after learning its requirements.
The suffix in بِهِ means “from it” and refers to الْعِلْمِ; the suffix in مِنْهُ refers to كَنْزٍ.
Recognizing the two pronouns clarifies the comparison: benefiting from knowledge corresponds to spending from treasure.