If you log them out, they will not be able to post in other threads.
If what you're looking for is so that cannot post in X, Y, Z thread, yet still be able to post everywhere else; than what you seek is what @HenrikHansen has suggest.
If you want X, Y, Z threads to only be accessible to X user group, then you should use such threads in another forum and setup permission settings for that forum.
There is no add-on that will force someone to be logged out of the whole site if they attempt to post in a thread and such thing doesn't make sense to me either. That would be equal to a ban
Correct. But they could log back in and post in other threads.
If what you're looking for is so that cannot post in X, Y, Z thread, yet still be able to post everywhere else; than what you seek is what @HenrikHansen has suggest.
You could redirect them via discouragement. set it to 100% of the time, and enter the url. Stick the users on discourage. Easy. All part of the core.
Of better yet create a usergroup called 'cantpost' (i have that).
Set the usergroup permissions so that they cannot like, create new thread or post a reply. Wack that usergoup onto those users.
... and were signposted to an add-on which does exactly that - allows you to stop someone posting in specific threads, but otherwise lets them use your forum as normal.
... which mentions threads again, but which also seems to imply that you are more interested in logging them out (ending their current user session) and not allowing them to log back in again.
Could you perhaps try to define what you need a little more clearly? Do you want to block people from posting in threads? or block them from posting altogether? or something else?