Any S Pen would be able to work with any device that supports the S Pen, they all use the same Wacom tech.
The only issue with compatibility is that the newest devices have bluetooth capabilities with the pen and that won't function unless you can charge the S Pen. I don't remember if the Tab S4 supports it or not, but if it does you would lose that functionality because you can't charge the Note S Pen without the Note phone.