It is a virus, and likely what happened is that someone who has the cold sore virus (it is a herpes simplex virus) kissed her. The annoying thing about the herpes virus is that it can be spread without any symptoms present. A person can be contageous and not know it.
My parents both had cold sores, as did my sister. I have never had one. I don't know why my immune system fought it off, although I do have an incredible immune system (it also fights itself which isn't so good LOL.)
There's nothing you could have done, nothing you can do. Since she is so young I would not try any herbal remedies (they are NOT FDA approved even for adults) and would only use meds if the doctor tells you to. However, know that she is quite contageous while it's open (I think once scabbed it's not contageous, like Chicken Pox--which is also a member of the herpes virus family.) So you might want to avoid playdates since at that age they mouth everything. :)