I encountered the following behavior:
If you pass a variable to a function and change it inside it, it will not change the variable at the parent scope as expected (without overriding the scope with $global: or something like this).
But if you do the same with complex objects the function will override the variable on the parent scope unexpectedly.
I think the problem you’re having is due to the type of value you’re passing in to the function, which is a hashtable. This is a reference type, so when you re-assign the value of the ‘A’ key, then it does it by reference to the original which is saved as variable $VarOut. There’s a decent explanation of the difference in reference and value types here:
You can see the difference if you change your script to only pass string values: