I think you're misunderstanding what a stale and inactive query means.
staleTime is the time in milliseconds that determines for how long the query is considered as "fresh". This means that as long as the query is marked as fresh, no network requests will be made after the first successful one and the data will always be read from the cache when needed. If the query is marked as "stale", then a background refetch can happen under certain conditions such as window focus (if enabled) for example.
A query is considered inactive when there are no observers registered. In more simple words, when all the components that use the query are unmounted.
A query's cached data can only be garbage-collected when it's marked as inactive for as long as the established cacheTime.
From what you explain, you configured the cacheTime to be 0. This means that as soon as all the components that use the query are unmounted, the cache for that query will be garbage-collected. If this is not happening, it's because one or more components that use this query remain mounted (the query is still active).