Once they have sucessfully scanned your illegal cargo your ship's ID number is known by all the police at that waypoint. Apparently not all the police in the solar system though because I was safe at the Manhattan waypoint after being attacked at the Norfolk waypoint.
I did not sell my illegal cargo at the first station in Norfolk, where the police scanned me so I can't say 100% whether they would have attacked me or not had I sold it there. I could get twice the price on Manhattan so I made a run for it. As soon as I left the station laser fire started pounding me.
However, once I sold the drugs on Manhattan, I headed back to the Norfolk waypoint with an empty cargo and they still attacked me. So I'm betting that it doesn't matter whether you get rid of the illegal cargo. You have to "clean" everything by getting rid of the ship since they have it's unique signature.
Once I traded my ship for a similar one on Manhattan I could travel to Norfolk safetly. Hehe very fun.
