How does the phrase "used to" work, grammatically?
This is more of a theoretical question, and so the answer depends a lot on what framework you prefer. "Used to" in this context is sometimes called a "quasi-modal" along with "want to", "ought to" and so on. Some linguists consider them the result of a historical process called grammaticalization, in which common collocations take on their own somewhat idiosyncratic grammatical properties.
I think there are tests you can use to demonstrate that quasi-modals don't behave the same way as infinitive structures (by making them questions, for instance), but this is not my specialty. However, I think a real infinitive use of "used to" would be as in:
(1) The saw was used to cut the wood.
I can't find a good article for this right now, unfortunately. Maybe someone else knows of one?
I'm not certain about the terminology, but I'm pretty sure "used to" is a set idiomatic phrase that marks verbs as being in the imperfect (past continuous) tense.
http://en.wikipedia.org/wiki/Imperfect#English
In this case, I'd say that the verb use is selecting the infinitive as its complement, making the to infinitive the direct object. The verb is tensed, ending up "used to". Another example would be "hope to blah". Here is an interesting paper on the distribution and semantic correlations between verbs that select for infinitives.
If "used to" is a set idiomatic phrase (i.e. not a tense), then why would it change its form from "use to" to "used to" for the sentence as it does in the positive? I.e. why not say "I use to smoke". "Did you use to smoke?" "I didn't use to smoke".
Chambers's 1939 dictionary tells us that "use to" is an intransitive verb meaning "to be accostomed to" only used in the past tense and pronounced /ust/.
Also in Practical English Usage, (Oxford),Michael Swan says that the formal form of the question and negative of "use to" is "Used you to go to the opera?" and "I usedn't to play football" etc.
In Ireland we've have remained faithful to these concepts and often "Quazi-modalize" the question and negative by saying "Usen't you go...?" and "I usedn't play..." etc. The problem I believe is that everybody argues the case in favour of what they themselves are, if you pardon the pun! "used to" saying themselves.
Unfortunately, English does not have an academy of experts that meet once a year, unlike Spanish.