This is controlled by the Discourse maximum session age site setting. That setting defaults to 1440 hours. Unless it is set to a very small value, it is not a reliable way to log out users. That is because it sets the amount of time that a user will remain logged in since their last visit. Setting maximum session age to a very small number of hours could also cause some annoyance for your site users.
I think your best approach would be to log users out of Discourse through the API when memberships expire. There is a code example of how to do that here: wp-discourse/lib/sso-provider/discourse-sso.php at main · discourse/wp-discourse · GitHub. You might need to get some help from a developer to make an API call to log users out of Discourse when their membership expires.