You unlock the ability to use this Gacha Machine in Chapter 7 - A City of Sadness, and any point beyond that.
A Gacha Machine has a varied amount of contents, where you can only get 1 of each, meaning no duplicates and wasting money, and can no longer use it when you've obtained all of the items. Each item costing 200 Dollars Each.
The machine by Mazu Temple has 3 Clothing pieces, 27 Gallery items and 10 Items. This means you'd have to spend 8,000 Dollars to fully obtain everything within this Machine.
As for its location, it's in the far bottom left of the town map, the one labelled as 'Mazu Temple'