The purpose of the "Hat in Mouth" drill is to teach infielders to keep their hands extended in front of them while fielding ground balls. Proper fundamentals of fielding a ground ball include extending a player's arms well in front of the body. With an infielder's hands held closely to their body, there is little room to react to a groundball and a smaller margin for error.
To help prevent players from holding their arms too close to the body, have your athlete take their hat off and put the bill of the cap in their mouth. This should be done so that the back half of the hat is pointing away from their body, and the flat bill is held in the player's mouth. Then, as a coach feeds them ground balls, have the player field the ball with proper footwork and fundamentals. Be conscious to notice if the player is reaching well out in front of them to field the ball. Having the bill of the hat in a player's mouth causes a vision block on the ground directly in front of them. This will force the player's hands farther out in front of their body position, so they can see themselves field the ball.
Beginning players, this drill should not be done at the same time as any other form of team practice. Beginning level fielders should concentrate only on the position of their hands while fielding ground balls. More advanced players (high school and above), the "Hat in Mouth" drill can be combined with a regular fungo routine, where players are also making throws and covering bases.