Is it ever happened that a swimmer was disqualified during a top-level competition (for example, the Olympics or World Championships) for a bad or incorrect stroke?
Emily Overholt was disqualified from the 400m individual medley at the 2015 Pan American Games for an incorrect touch at the end of the breaststroke leg: both hands must touch the wall at the same time in breaststroke and butterfly. Thiago Pereira was disqualified from the men's 400m individual medley at the same games for the same reason.
In addition to the ones listed by Philip, there have been many other instances of swimmers being DQ'd in top level meets, sometimes being overturned, sometimes not. The one that comes to mind is in 2004, Aaron Piersol was DQ'd for turning over onto his stomach too early in the 200m backstroke. It was later overturned, and many felt that the initial DQ was because he was critical of FINA and a Japanese swimmer, Kosuke Kitajima, for taking extra dolphin kicks in the breaststroke.
Many times this is due to techniques and rules changing, such as the initial allowing of dolphin kicks on the backstroke, later reduced to 15m from the wall, not allowing dolphin kicks in breaststroke to allowing one (And this is very much abused) on the pushout from the wall. In addition, what might be allowed in an individual stroke race would not be allowed in a medley or medley relay.
While the file at this link is for the Masters FINA championships, you can go through and see DSQ for using tape on the body, using aids, no touch at turns/finish, illegal kicks/turns, etc. This link shows the 2015 FINA World Championships, and it shows 14 people disqualified, but no reason given (Most will be a false start, that's the most common infraction).