Basically, it involves exploiting some vulnerabilities(for example, a buffer overflow) in Linux kernel to gain advanced privileges. The exact technique used varies with devices and Android versions.
This Stackoverflow answeranswer should give some idea.
Androidcentral has a page that gives more information on root.