The attached Ship Pointing mod shows different behavior depending on whether the playership rotation was last set by the keyboard or the mouse.
I assume it is a mouse bug.

Start a game.
Rotate the playership with the keyboard keys.
Select 'S' for the Ship's Interior screen.
Select 'P' for the added "Point" action.
The playership undocks from the screen and the code runs as expected. The playership rotates, either clockwise or anticlockwise to the nearest cardinal direction in 5 degree increments. The code has then finished and stops. Debug output confirms this.

Next rotate the playership with the mouse. Any direction will do, it doesn't seem to affect the outcome.
Again select 'S ' then 'P' to run the mod.
On undocking the playership vibrates continually within a few degrees. It does not repeatedly adjust the playership rotation as would be expected. Rotating the ship to the desired cardinal direction with the mouse will stop the vibration but using the mod again will show the same errant behavior.
However rotating the ship with the keyboard will stop the vibration and restore normal function, the mod will turn the ship to the desired direction and stop. Additional uses of the mod will now run as expected.

Based on the debug output possibly some hard-coded mouse code is interfering with the setting of the playership rotation.

Something similar also happens in AP's One-Frame Turn mod. Using the mouse before using the mod interferes with the mod and stops the playership rotation being adjusted.

05 ShipPointing for ul Ministry.xml
nms 5 Sep 2019:

Is the mouse visible as the vibration is happening? If so, the ship is correctly trying to turn to face it. If not, then I guess the game incorrectly thinks it's in the mouse control state.

relanat 5 Sep 2019:

Is the mouse visible as the vibration is happening?

Yes. So that is what is happening. The mod code sets the playership rotation then the mouse sets it somewhere else, repeating until the code stops. Possibly we need code to reset the control state?

assumedpseudonym 5 Sep 2019:

 Wait, turning in five degree increments? It should be turning in three degree increments for 120-facing ships.

relanat 6 Sep 2019:

120 facings was rare back when the mod was written but thanks for the idea. I'll trial 3 and 6 degree changes to see if they appear smoother. Nice one!
EDIT: I think I've worked it out. 5 was used so 40 facings ships would turn a facing when the code ran. With 9 degree intervals the ship rotation had to be moved at least 4.5 degrees for the image to rotate (maybe).
40 facings ships don't turn with the rotation value set as 3 degrees.
The released mod will use 6 and handle 40 and 120 facing ships. Not tested but 20 facing ships probably won't turn.

nms 6 Sep 2019:

Unfortunately, I don't believe it's possible to exit mouse control state via script. Currently, it's also not possible to disable rotation without totally disabling a ship, but I have requested this for other purposes, so it might get added.

george moromisato 29 days ago:

In 1.9 Beta 4 we exit mouse control if the ship rotation is set explicitly via script. This should solve the problem with this extension.