It comes down to buying multiples of the same set rather than one of everything. Armies need repetition, and repetition is where the cost sneaks up on you.
For a medieval force, that means several cavalry sets if you want a mounted wing, archers for the ranged line, and knights for the front. If you want a battery of catapults, buy that one set five times. Two watchtowers instead of one is the same principle applied to fortifications.
Be warned that this adds up fast. A respectable LEGO army is one of the more expensive collections you can start, so decide on a scale you can live with before the first purchase rather than after the fifth.