Valentino Rossi is the rider usually credited as the first to use the technique in the early years of four-stroke MotoGP, when he out-braked Sete Gibernau in the last corner at Jerez in 2005 (running the Spaniard off the track in the process). However, if you watch videos of 500cc Grand Prix races from the early '90s, you will occasionally see Kevin Schwantz, Wayne Rainey and others making similar moves.
Most riders do not (or cannot) offer much in the way of an explanation when asked why they put their legs out, other than it feels comfortable and helps in some way. That has not stopped experts and amateurs alike from speculating on the physics behind the leg dangle and what advantages it offers.
One theory is that with the leg extended toward the inside of the turn, the bike can be kept more upright as the rider turns in, allowing the brakes to be used deeper into the turn. Another is that the extended leg lowers the combined centre of gravity of bike and rider, keeping the rear end on the ground under hard braking. Aerodynamics has been cited, with the inside leg acting as a sail to help slow the bike as well as help it turn into the corner.
The theory that I think has the most merit is that hanging a leg off helps physically turn the bike into the corner, and this particular explanation does fit in with body steering as I discussed https://www.insidemotorcycles.com/blogs/item/1051-body-steering.html">in my blog last week. If your inside foot is off the peg and close to the ground, the act of raising it up (and returning it to the peg) will help to rotate the bike around its roll axis and lean into the corner.
All of these theories have at least some basis in the physics involved. The real answer may be that it's some combination of the aerodynamics, centre of gravity and weight transfer that adds up to a benefit felt by the rider and/or measured on the stopwatch.
Just as many other riding techniques become common practice by filtering down from the top rider, the other MotoGP riders took their cue from Rossi and imitated his leg dangling antics. Whether the advantages are real or perceived is almost a moot point. If a rider thinks that hanging a leg off the side of the bike (or sitting backwards on the seat, or wearing a red shirt, or...) helps him go faster, then that's what the rider will do. But here I think the benefits must be real, otherwise it would have faded away over time; I can't see the MotoGP riders expending energy on an unnecessary technique.
Whatever the reasons behind the leg dangle, there are two important aspects to note: One is that your body is a versatile tool when it comes to riding a motorcycle, and there is much more involvement than just turning the bars and moving your butt off the side of the seat. The position of your feet and legs, how you hold your arms, where you place your upper body, and even how you angle your head all affect how the motorcycle behaves. The other is that you shouldn't be afraid to experiment with new techniques, even if it's something no one else is doing; it may just be that the other riders take their cue from you.