The standard conventions employed by Shakespeare in achieving his resolution to this incredibly confusing play that threatens to get out of control is to start off by making it even more confusing. Now that both Olivia and Orsino are on stage, it is possible for both to lay claim on Cesario, and the hapless Viola is left to be completely confused by Olivia's claim that they are married. Then the introduction of Sebastian to the scene creates absolute wonder and amazement, as expressed by Antonio when he sees before him what looks like two Sebastians:
How have you made division of yourself?
An apple, cleft in two, is not more twin
Than these two creatures. Which is Sebastian?
The moment when both Sebastian and Viola are on stage together of course results in the confusion of the play being sorted, as there is now no opportunity for further mistaken identity, and the truth is able to come out. However, note the language that Antonio uses. Sebastian and Viola are so alike that it appears as if Sebastian has "made division" of himself. This explains how easily everybody was so confused by their appearance. The resolution is now able to take place as everybody, not least Sebastian and Viola themselves, understand what took place.