Two-time Madrid Open champion Simona Halep failed to capitalise on a commanding position as she was eliminated by Elise Mertens.