Here is the answer with
19 pawns
I am not sure this is optimal:

Here is the solution.
0. h1 1. b1 2. f5 3. h7 4. g7 5. f7 6. f6 7. d6 8. h6 9. g5 10. d8 11. h8 12. c3 13. c8 14. b7 15. a7 16. d7 17. a4 18. a6 19. e2
To approach these types of problems, it may be helpful to first consider a smaller board size, such as a 3x3, 4x4, or 5x5, and then determine the corresponding solutions.
3x3

4x4

I have manually constructed both of them using the methodology described below;

To begin creating the pawn board, it's best to first determine the end pawn - where the queen will ultimately end up. This end pawn should only be accessible from one other pawn on the board. To achieve this, we need to carefully consider the placement of the other pawns in relation to the white pawns on the board.

I have chosen (2,2) one for the pawn to the end pawn. Moving forward, it's important to avoid placing any other pawns in the locations currently occupied by the white pawns. (see above) While there may be solutions that involve placing the Queen among the white pawns, for the purposes of clarity, I will refrain from considering such scenarios at this time. We should place black pawns in the remaining empty spaces and position the queen at the top right:

The process becomes more complex when dealing with a 5x5 or larger board, but the underlying principle remains the same - identifying an end pawn location that can only be reached by a single pawn via the queen. For example, for my solution above for 8x8, the end pawn is e2 and the pawn before that is a6. there is no other pawn can reach to e2 by queen. Every solution has to have such two pawns to start with.
I will try to explain how to apply this with 5x5 or more later hopefully :)