Should I have intervened?
You did intervene, in a way. You were present, and you assessed the situation and determined your daughter wasn't in immediate danger.
Children need to be able to rely on their parents to step in to protect them when necessary to avoid harm, but it's a personal parenting decision to shield them from all possible negative interactions. Some parents will say they would never let another child lay a hand on their own if they could help it, and some will handle it just as you did.
Stopped the boy hitting her?
You could have, provided it was done merely by placing yourself between them and/or carrying your daughter away.
There's not much you could have done with the other child, since you should never physically touch another person's child without express consent or reasonably implicit consent (such as when you're supervising them), unless it's to keep them from immediate harm, in which case you're morally obligated to act.
My primary reasoning for not touching another person's child is legal liability. Parents can be quite protective of their children, and somebody else "handling" them can quickly escalate a situation.
I think the socially acceptable response to physical altercations between children is usually to physically remove your own child, or tell them to leave the situation on their own, anyway.
Shown her that such "violence" should be met with appropriate reaction? Or was I right to have let her handle the situation on her own.
I think this question is better answered on its own. There are some relevant existing questions on this topic already:
How to get 4 year old to stick up for himself but not turn into a bully?
How do you teach toddlers to defend themselves?
Teaching children how to fight back
What impact did my lack of action have on my daughter? Will she feel "unsafe" with me because of that? Will it encourage any reaction from her in case such thing happens again?
Children generally trust their parents to attend to their safety and well-being. You choosing to not take action was essentially a signal to your daughter that she wasn't in any real danger.
I'm sure she was confused by the incident, as you expressed, but that's to be expected. It's really confusing to just be thwacked in the head by a stranger.
By not making a big deal out of it, or drawing attention to it, you also communicated to your daughter that stuff like that happens sometimes and life just goes on. If you don't make it a big part of her day, then she likely won't either. Events like that are transient and not harmful overall.
As for communicating that what the other boy did was not okay, the other parent handled that. They removed the boy from the situation, which was a clear signal that what he was doing was not acceptable.
I doubt she'll feel unsafe because of that isolated incident. As you said, she wasn't really harmed. If this was a repeated pattern of behavior towards your daughter, then I'd assume she'd develop a behavioral response. As it stands, I wouldn't expect her to do anything more than possibly avoid that other boy if they run into each other again (but young children can often quickly overcome such conflict as if it never happened).
What would you have done?
Probably what you did. If the other parent hadn't stepped in then I would have probably said, "Don't hit," while walking towards my little one to remove them if necessary.
Depending on the other parent's demeanor, I might have even offered an understanding smile or comment to let them know that we didn't hold any grudges, but that those things happen.
Depending on the other child's demeanor, I may have found a way for the two kids to play something else, together. At that young age, children don't always intuitively know how to interact with one another appropriately, so we as parents can help facilitate their ability to make new friends, even if it's just a playground friend.