The size-mass relation at rest-frame 1.5 μm from JWST/NIRCam in the COSMOS-WEB and PRIMER-COSMOS fields