This is due to a phenomenon called Thermal Expansion that occurs in materials when temperature rises.
You may think at mercury as a group of, say, students sitting at their desks in a classroom. They oscillate and move around their chair (trust me I know that because I teach and it is difficult to maintain them still!) and when you increase the temperature it means that they receive energy and start to oscillate more and more.
Now in the first case you could measure the width of your classroom of students as x but when they start to oscillate you'll measure a larger width due to the fact that your students now occupy a larger area (oscillating).
Mercury does the same and to cope with the increase of volume (in this case) it rises up the glass column when temperature increases.