The painter’s sketch for his portrait of Madame X allows us to see his subject quite differently – and fills a long-standing gap at the Frick Collection