The UNION operator combines all the rows from one query with all the rows from another, eliminating duplicates, and forming a single list. The hash operator builds a hash table from the upper input and probes that table with the lower input. I can see how this would work to implement a UNION, given the row-at-a-time pull model the execution engine uses. I imagine it works something like this.
The Hash operator is asked for a row. It, in turn, pulls a row from the upper table, hashes it and compares it to its current list. If it is not found in the list it is a new value, it gets added to the hash list and also returned to the calling operator. This continues. Eventually a row is read that has a match in the hash table. That row is rejected (UNION eliminates duplicates) and the next row read. Eventually the upper input is exhausted. Processing continues with the lower input, reading rows, rejecting matches and passing on fresh values, until it, too, is exhausted.
Under what conditions would a hash match be used instead of another operator? The trivial answer is because the optimiser has determined that the cost of a hash operator, for the given datasets, is less than the cost of any other operator that could perform this task. More specifically (I'm extrapolating somewhat from joins) hash match typically occur for larger datasets without appropriate sorting.
Here's an example that shows the usage. I have a Numbers table, which I've copied to create dbo.Numbers and dbo.Numbers2.
select * from dbo.Numbers
select * from dbo.Numbers2
uses a merge join. Unsurprising, since both tables are ordered appropriately for the query. By deleting the primary key on one table, however, and converting it to a heap, the optimiser no longer has a guarantee of ordering and it uses a hash operator:
Note the naming, however. This is Hash Match (Union). Changing the query to a join
select * from dbo.Numbers as n1
inner join dbo.Numbers2 as n2
on n2.Number = n1.Number
Also uses a hash match
This time it is Hash Match (Inner Join). The properties for the Hash match in each query differ.
As for table size, with 10,000 rows in dbo.Numbers a hash match is still used. With 5,000 a sort and Merge Join (Union) are used instead.