An officer is responsible for the defense of his position.
Anderson did not fire on Confederate forces until the fort was fired on.
He informed them that he would fire on them if the belligerent war fleet that Lincoln sent received any return fire.
No man is going to let someone shoot at him without returning fire, and Anderson simply made it clear that he would be helping the aggressor.