As Mercury is inclined by 7 degrees relative to the orbit of the Earth (the ecliptic) at any given time it may be above the ecliptic or below. However there are two times during its orbit when it crosses the ecliptic. These are known as "nodes".
A conjunction occurs when the planet is vertically above or below the sun. A superior conjunction happens when the planet is on the far side of the sun, an inferior conjunction happens when the planet is closer to the Earth than the sun.
When a node occurs at about the same time as an inferior conjunction, then the planet will appear to travel in front of the sun. Whether it travels through the middle of the solar disk, or through the upper or lower part, depends on whether the exact time of the node occurs just before the conjunction or just after.
In May 2016, Mercury crossed the ecliptic at about 08:00 (utc), and had it inferior conjuction at about 15:00. It was a little below the ecliptic by the time of conjunction, but still close enough to cross the solar disk.
The exact position of Mercury also depends on the location you are viewing from on Earth, a fact that Edmond Halley noticed could be exploited to calculate the distance to the planet, and by extension, the distance to the sun.