The naval officer symbolizes war, which creates irony between the war he is fighting in and the war that the children have been engaged in.
The naval officer lands on the island just in time to save Ralph's life. His presence reduces the on going battle between the children to just that, fights between children, and it causes him to reflect himself on the war that he is engaged in. He finds himself shocked at the savagery the children had been reduced to.
The irony is that as the naval officer expresses out loud his surprise of the savagery the children resorted to he turns to look at his own ship and realizes that he too is engaged in the same.