The motor should remain attached after you rotate it. You can reattach the motor by removing the lightbulb first, and then insert your finger inside. With your finger in, pull the mirror and hold it. Unscrew the black screw, and you will feel the mirror moving as you unscrew it. That is how you adjust the headlight when it is fixed on the car. If you cannot feel the mirror moving, that means the black screw is not attached to the mirror, and you will have to solve that first.
Now, with the black screw maximum unscrewed, try to insert the motor and slide it into possition... do not try to push it in. The motor has a short stick that goes into the headlight. That stick has a rounded head that needs to be inserted into its place from one side. Do not push it.
Its a little tricky, but you can do it