Index that is not used, yet influences query
When you create an expression index, it causes PostgreSQL to gather statistics on the that expression.  With those statistics on hand, it now has an accurate estimate for the number of aggregated rows that the query will return, which leads it to make a better plan choice.

Specifically in this case, without those extra statistics it thought the hash table would be too large to fit in work_mem, so it didn't choose that method.