Did you recalibrate the motor? If it and the sunroof casette are not in the exact same position they were were when you removed the motor, you need to resync the two together.
If the sunroof is completely open, set the sunroof motor to be fully open too. That is with the sunroof motor plugged in, press the switch so the motor spins to the first open position. Like 80% open. Press once more in the same direction until it stops again.
This is the fully open position as far as the motor is concerned. If your Sunroof is fully open, you can reinstall the motor and press the button until the motor reaches the fully closed position , but not tilted. using the adjustment tool. (kind of Z shaped Allen wrench, tun the motor manually until the top is positioned closed, not cracked, not high, but a mm below level in the rear. Then pull off the motor and resync to fully closed. Your sunroof cassette and motor should not be aligned.
If you don't properly sync the motor and the cassette, the motor can over tilt your sunroof and break the lifting rods then you have a bigger repair.
There are threads around on this procedure. Cheers and good luck.