By default the next and previous product URLs navigate to to next or previous product within all the products in the catalog.
In case you need more robust feature you can enable Next & Previous Products Inside Category located in Product Settings > Catalog Design > Product Page.
After you check this feature and save the settings the Next and Previous product URLs will navigate to the next or previous product inside the category from which the user came to see this product.
If the user comes from all products page than the URLs will point to the next or previous product within all products.