If a ship is just flying from A to B and it's not harvesting or trading, it cannot be stopped. Only ships that are harvesting or trading can have their AI cancelled.