A Magnetar Origin for the Kilonova Ejecta in GW170817