I read the book Attack on the Liberty by James Ennes, an officer of the USS Liberty, a vessel which was attacked by the Israelis in June 1967 and who was aboard during the attack; according to him and every other member of the crew that survived, there was no way the Israelis could have mistaken their ship for an Egyptian destroyer or freighter as the Israelis claimed. The ship does not resemble a destroyer or any other type of warship in any way, and besides a couple of .50 caliber machine guns, it carried no other weapons. Although it was once a cargo ship and could have easily been mistaken for one, the array of antennas alone strongly suggested it was an intelligence-gathering vessel, which indeed it was. However, its paint scheme, large U.S. flag flying, and the large hull ID (in the Liberty's case, AGTR-5) painted in large characters on both sides of the ship's bow should have left no doubt it was a U.S. Navy ship. Several Israeli aircraft flew low and slow over the Liberty before it was attacked, and the weather was crystal clear and the sea was calm in all directions for many miles. The Liberty itself was cruising at five knots until it was attacked, which is very slow even for a civilian freighter. Warships typically go much faster than that, even when cruising, and especially when in a war zone.
After saying that, the ship, being as vulnerable as it was, should have never been so close to the war zone in the first place. A message was transmitted ordering it to move out at least 100 miles from the coastline, but the message wasn't received by the Liberty until after the attack was over. The U.S. had a habit of placing highly vulnerable spy ships dangerously close to hostile areas, as we found out again in 1968, when the North Koreans seized the USS Pueblo. Although the attack on the Liberty was bad enough, the North Koreans (and the Soviets) got an intelligence and propaganda windfall from the Pueblo incident. The Pueblo is held by the North Koreans to this day. Back in 2001, a U.S. spy plane was forced down on Hainan Island (a Red Chinese territory), which, although not comparable to the Pueblo incident, once again underscored the risks of exposing ships, aircraft, and their crews on intelligence-gathering missions in such close proximity to their targets. The Iranians captured a top-secret (not anymore!) stealth drone that apparently had a mechanical failure and essentially glided right into their hands a couple of years ago, which they undoubtedly learned much from.
In fairness, it is not uncommon for neutral ships to be attacked by one or more warring parties when they are in a war zone, or ships being attacked by "friendly" aircraft or ships by accident. One of the reasons the U.S. entered WW1 was the re-introduction by the Germans of unrestricted submarine warfare which resulted in numerous American ships being sunk or damaged, and several U.S. Navy ships were attacked and sunk by the Germans prior to a formal declaration of war (by Germany, on December 11, 1941). The USS Panay, a small river gunboat, was sunk by the Japanese in 1937, and the USS Stark was nearly sunk by the Iraqis in 1987, with the loss of 37 lives. However, neither of those incidents remains nearly as controversial as the attack on the Liberty, and both the U.S. and the Israelis have been less than forthright in providing explanations for a seemingly obvious and egregious attack on a vessel that was in no way engaged in hostile action or trying to conceal itself. If the Israeli intent was to sink the ship, they actually performed very poorly; 30mm cannons, rockets, and napalm are far from ideal anti-ship weapons, and their torpedo boats fired five or six torpedoes, with only one hitting the ship, although that one tore a huge hole in the ship and caused the majority of the deaths during the attacks. It’s been said that the U.S. and the U.K. have a “special relationship”. I guess the relationship between Israel and the U.S. is “even more special.”