Magic!

... not really. The system uses a Bayesian-like method to check the content and title of your question, looks at previously asked questions with similar word choices, then suggest the tags that deems appropriated (or so it should be). [Here][1] you can see the original post describing how it works.

That's why retagging is important, because it teach the system which questions should use which tag. 


  [1]: http://meta.stackexchange.com/a/212310/213575