The ruling deals a major blow to his signature economic policy and represents a stinging political setback.