I think Shakespeare wrote about mistaken identity because while it is very funny it also relates to larger messages about life and who we are. Why are people so quick to make these incorrect associations? What is the consequence of mistaken identity?
Gosh! This play is absolutely typical of many Shakesperian comedies in focussing on mistaken identity. The key strategy of using twins with hilarious consequences is something that is not unique in this play, but clearly leads to widespread confusion with practically every character being taken in at some point - except perhaps for Feste, but that is another discussion! What is amusing is the way that Sebastian and Viola are left confused as well by the way that others respond to them - confusion all round, making this a hilarious comedy, with nonetheless serious themes and messages.
Mistaken identity is huge in this play - without Viola and Sebastian being twins, and Viola deciding to dress as a boy to protect herself when she thinks her brother drowned at sea, there really wouldn't be a whole lot happening in this story!
Viola, disguised as Cesario, is employed by Duke Orsino to woo Olivia. The problem, then, becomes this - Viola, truly a woman, falls in love with Orsino, but is unable to demonstrate this love to him. Olivia, believing that Viola is a man, falls in love with "Cesario." Things go blithely along until Sebastian shows up (not really drowned at sea), and everyone thinks he is Cesario! This is why Sir Toby and Sir Andrew pick a fight with him toward the end of the play, right before Viola and Sebastian find each other again - because they think he is really Cesario and is refusing to go speak with Olivia!
Lots of confusion, but all sorted out when the twins discover that the other is still alive:
If nothing lets to make us happy both
But this my masculine usurped attire,
Do not embrace me till each circumstance
Of place, time, fortune, do cohere and jump
That I am Viola-- (5.1)