In the simplest terms, grooves create friction when the surface of the ball encounters the sharp edges of a groove. This contact creates friction and the ball generates spin.
What do grooves on golf clubs do?
Golf club grooves have the exact same function as the treads on a tire. They allow water and debris to move away from the ball's point of contact to provide cleaner contact with better control. Striking a ball from the rough can be unpredictable when there is a lot of debris between your club and the ball.
Is sharpening your grooves illegal?
Groove sharpeners are technically not illegal to use, but you'll need to be careful in how you use them to avoid game disqualification. The main point to remember is that the shape of a groove cannot be changed by the golfer. This is considered illegal.