If you pay for/manage the internet connection:
To ensure someone else's internet traffic who's on the same network doesn't trace back to you, you could configure your router to force all traffic through a VPN for certain devices. That way, it would be more difficult to trace anything illegal that someone else does on your internet connection back to you. Make sure to choose a solid VPN provider that has solid encryption and doesn't keep logs.
The article linked below is specific to NordVPN, but the instructions will be applicable to any router, you'll just need to input different VPN credentials and certificates.
If you are using someone else's WiFi:
Since you don't have any control over the network, you should always use a VPN to prevent anyone else on the network from intercepting your data. I would also change the MAC address of your device (if you can) because if the router keeps logs, it will normally store a copy of it in a log, which could be used to identify your device.