Shape optimization problems on metric measure spaces