John Swinney has been warned schools could face a Sandie Peggie-style legal dispute over gender self-ID policies.