Iranian warship hit by US torpedo did not carry ammunition, say Indian sources
(www.middleeasteye.net)
where you know it will be defenseless
This is the reason why attacking military and attacking civilians are considered different. Civilians are defenseless. They do not carry weapons. Attacking a defenseless warship, where it went for a military exercise with a non-adversary country is cowardly. Ambush is not the problem here.
Edit: (from the post link)
According to reports, the rules of the exercise stipulated that no ammunition was allowed on participating ships.