The original vowel sound in both words was the rounded high short <u> sound of put, which was much more common up through the 17th century than it is today in American English speech. In most words this high short <u> eased to the unrounded low short <u>, as in butt, and in words like but, which are usually weakly stressed, it reduced to schwa. This easing makes pronunciation slightly easier, which is usually the reason for any pronunciation change.
However, several words kept the old high short <u> pronunciation, usually following the labial consonants [p], [b], [f], or [w], and especially if the vowel was in turn followed by [l] or [sh], as in pull, bull, full, and (with <oo>) wool, and in push and bush. There is something of a tangle here, with words like woman, butcher, puss (without the following [l] or [sh]) and cushion (without the initial labial consonant) also retaining the old pronunciation. And, of course, your word put.
Such words tended to resist the unrounding and lowering of the put vowel to the but vowel due to constraints put upon the pronunciation of the vowel by the preceding and following consonants: The preceding labial consonants worked against the spreading of the lips necessary to pronouncing the but vowel. And the various following consonant sounds encouraged a pronunciation of the vowel higher in the mouth. Both effects worked against the easing of the high round put vowel to the lower unrounded but vowel. Thus the seemingly inconguous different pronunciations.