
Question: Why does Dumbledore purposely hit Ron's injured leg?
Answer: Ron had previously bragged to Hermione about how bad his leg was injured, and had lied and said his leg might be chopped off. When Dumbledore later hits Ron's leg, he is saying that a child's voice no matter how honest and true. He is giving Ron a little payback for exaggerating.
Highly unlikely Dumbledore knew what Ron told Hermione at the Whomping Willow. Ron's leg was seriously hurt, so he wasn't "bragging" about it, nor did he lie. Ron, who is a bit of a hypochondriac, was simply embellishing to be more dramatic and to gain Hermione's sympathy. Hardly anything Dumbledore would consider worth giving him "payback" by inflicting pain.
Answer: This didn't happen in the book. It appears to be done purely for comic effect in the movie, showing Dumbledore's eccentric and quirky nature. He's seemingly oblivious to what he's doing and how it affects Ron.
raywest ★