Background info:
Docking unfactioned ships to a factioned base, and that dock has no permission module will put the faction signature of that base on the unfactioned ship. When the ship is undocked, it is again neutral.
Docking factioned ships to a factioned base is only possible if there is a permission module on it. This allows any other faction to dock and it should remain unchanged.
Now...I did notice an exploit with this and I assume that happened with you: Docking to a rail with permission module next to it should not touch your faction signature (even if you are neutral), even moving that entity to another rail with no permission module next to it should not change it.
This seems to be the case, till the sector gets unloaded/loaded again, then it will inherit the faction signature of the entity it is docked to. Even if it was factioned before.
It's not too harmful for allies, but for public server docks it can be frustrating/game breaking.