Matrix ensembles with global symmetries and ’t Hooft anomalies from 2d gauge theory