Fixing behaviour of where unscoping to not leak

As per issue #17738 this will prevent calls to .unscope from
altering the original query's where_values collection.

The new test in where_chain_test.rb passes.

The test 'HasManyThroughAssociationsTest#test_has_many_through_unscope_default_scope'
now fails and needs more investigation.

Submitting this as a PR despite the broken test so that other contributors can investigate the new test and help figure out the underlying cause (I had a brief look but couldn't see why it started breaking after the change).