Iptables has support for forwarding network traffic via a proxy, the keyword is “tproxy”.
I don’t think you can use socks5 directly, but you can translate tproxy to socks5 by installing squid listening on localhost for tproxy connections and setting the socks5 as an upstream proxy.
If it reads like a bunch of obsolete tech, it’s because it is, but it gets the job done.