You need to 301 redirect to the last page in pagination if page does not exist.
The last page of pagination: https://test.com/product-category/test/page/42/
Example of page with the addition of other characters https:/test.com/product-category/test/page/42888/
To configure the 301 redirect for such pages to the last page of pagination https://test.com/product-category/test/page/42/
prompt as such to implement, and where