Ghost-free higher-order theories of gravity with torsion