They didn’t fire on the ships. The Charleston batteries fired on United States Property, i.e. Fort Sumter.
It stopped becoming US property, the minute SC seceded.
And I suppose that firing on British troops on Lexington Green was wrong as well. At least the South seceded before the first shot was fired.
They fired because of the ships. Had Lincoln not sent those ships, they were going to wait Anderson out. Anderson had already started drafting an evacuation order.
If you read the details surrounding Beauregard's battery assignments, he held numerous batteries in reserve just for the ships. In fact, I believe I read that he held the bulk of his batteries in reserve to deal with the ships. He only attacked Sumter with part of his forces.
Once again, I will remind people that the Confederates knew why the ships had been sent, and it was only after the ships had been sighted rendezvousing at the designated point that Beauregard decided he didn't have any more time to give Anderson.
A man would have to be a fool to allow someone to attack him from two sides at the same time.