Typically, anyone can participate but there is a formal signup and registration process, and there is often a small fee. The point of the walk is to raise money for a charity, so there are quite specific rules and the charity makes sure it gets its money. For example, to participate you may need to promise to raise at least $X--and they may want your credit card number so they can be sure they get the $X.
It used to be common for walkers to walk as far as possible, and donor to promise to pay so many dollars per mile. For health and safety reasons, and because donors prefer to know in advance just how much they are donating, "dollars per mile" is much less common.
It is a lot more fun than just giving money directly. The walker gets to participate in a group activity and get healthy exercise. Donors feel that the walker is "earning" their donation and therefore "deserves" it. And it's a lot harder to turn down a friend who says "sponsor me" than to turn down a charity that says "donate to us."