How did "used" get its meaning?
Solution 1:
It may come from the (largely archaic) sense of use the noun meaning habit; 'It is his use to do so' is not uncommon in Shakespeare, and custom and use is good legal justification in certain circumstances (I don't at present feel inclined to revisit the question whether there is a difference between the two words). Interestingly, there is a line in Twelfth Night, "How use doth breed a habit in man!", which may indicate a gradual line from one use, to common use, to use/custom, to habit. But this is largely speculation.
Solution 2:
It's not the meaning of the word used (pronounced [yuzd]) that's the problem. It's the meaning and usage of the two idioms spelled "used to", pronounced ['yustə], and never pronounced [yuzd tu].
The first idiom, which is the one you cite, is actually "(be) used to"; it's a predicate adjective construction, and therefore needs an auxiliary be, which holds the tense morpheme. "(Be) used to" takes a human subject, and refers to that subject's level of familiarity with something.
- Bill is used to sleeping on the train means that he frequently does it.
- Bill was used to sleeping on the train means that he frequently did it.
The other idiom is a true verb and thus requires no auxiliary verb, but its tense is fixed (past) and can't be changed. Also, there's a spelling problem with rules like question formation and negative formation that require Do-Support.
This idiom has a very complex meaning. X used to VP asserts that X VPed for some time in the past, and presupposes that X no longer VPs Thus,
- Carter used to be President asserts that he was once President and presupposes he's not now.
whereas, by contrast,
- Carter isn't President any more asserts he's no longer President and presupposes he once was.
As to why "used" is used this way, it really isn't.
Native speakers don't feel that these idioms are connected with the verb to use. That's why we don't say things like
- *Bill used frequently to come here.
- *Bill is used completely to the noise.
which would require the normal [yuzd ... to] pronunciation, instead of saying
- Bill used to come here frequently.
- Bill is completely used to the noise.
which keep the [yustə] pronunciation that identifies the idioms.