Inconsistent behavior with user_logout function
As it turns out,
return new TrustedRedirectResponse('https://example.com'); 
was the culprit here.
TrustedRedirectResponse extends CacheableSecuredRedirectResponse, as a result the function was cached, and user_logout was not called even when I visited the  /customlogout
The workaround for this is adding the following lines in your routing.yml
options:
    
  no_cache: TRUE