This is most likely because the default parameters in the uStepper library does not fit your application. Here’s a short description on what you could do to tune the parameters:
The first two parameters tells that we are doing Drop-in and that microstepping is 1/16 from the printer/cnc controller. The third parameter is the amount of steps that must have been missed for the PID to kick in. The third is the number of steps that you are still of before the control stops again. It is advisable to have some hysteresis to avoid oscillating behavior. You can move it to for example 5,0 or 10,0 depending on your mechanical setup and the following PID parameters. The next parameter is P, start with setting this to e.g. 1-5, the next is I, start with a value of maximum 2. The last is D, this you can set to 0 as a start. For info on what P, I and D do, please read on the very nice PID wiki page
Another reason could be that the encoder magnet is slipping – especially when shifting direction. This can be fixed by using double adhesive tape to make the magnet sit tighter to the shaft.