i've had a few old bikes that due to wear etc the hole in the sprocket is a little larger than it should be. if your not careful to center the sprocket, you run into the problem you got.
now this usually isn't the case. most main sprockets are press fit. wheres no room for error, but i have ran into the exception that bolts on. the rear sprocket could be worn.
now if the main sprocket has recieved an impact and is no longer circular, same problem.
a loose rear drop out (specially those presss fit tack welded type) or a loose rear wheel nut would do the same.
a loose rear hub (ie bearings) will do the same. (see if you rear wheel wobbles from side to side
and the worst of the worst. bent crank